I agree with you, Ariel... got your point, doing a test with 'html' can catch elements within the 'head' or itself, also... :-)
Another example of the utility of a feature like this, Dan: var uniqueDiv = $('div#unique'); uniqueDiv.length == 1; uniqueDiv.remove(); uniqueDiv.length == 1; // OK... not an expected behaviour, is it?! ;-) Ariel, any ideas for using an expando to persist the information, but without having to traverse through all the childNodes and setting a lot of properties? Maybe something using $.data(jElement)? Diogo Baeder On Sat, Nov 29, 2008 at 3:01 PM, Ariel Flesler <[EMAIL PROTECTED]> wrote: > > That's not the described behavior: > > var $div = $('<div />'); > $div.inDom() == false; > $div.appendTo('body'); > $div.inDom() == true; > > -- > Ariel Flesler > http://flesler.blogspot.com > > On Nov 29, 2:59 pm, "Dan Switzer" <[EMAIL PROTECTED]> wrote: > > > I'm new here (and in jQuery), but even though I'd like to propose some > > > simple but usefull method to the jQuery object (at core.js) to tell > > > the API user if an element exists in the document. I've tried to build > > > one as follows: > > > > > [CODE] > > > (function($) { > > > > > $.fn.inDOM = function() { > > > return !!this.parents('body').length; > > > }; > > > > > })(jQuery); > > > > > jQuery(document).ready(function(){ > > > var jEl = $('.someExistingClass'); > > > > > // Should be in DOM > > > console.debug(jEl.inDOM()); > > > > > // Removing the element > > > jEl.remove(); > > > > > // Should NOT be in DOM > > > console.debug(jEl.inDOM()); > > > }); > > > [/CODE] > > > > I'm not sure how useful this would be, since this tells you the same > thing: > > > > var inDOM = $('.someExistingClass').length > > > > If the length is 0 it doesn't exist, otherwise it does. Since the > > number 0 equates to false and a positive integer equates to true, this > > tells you the exact information. > > > > The only thing it potentially does is improve visibility. In that case > > I'd opt for the name exists() instead of inDOM. > > > > And you could just do: > > > > jQuery.fn.exists = function (){ return this.length > 0 } > > > > (I did a check to return a true boolean of either true or false.) > > > > -Dan > > > -- Diogo Baeder http://www.diogobaeder.com.br --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---