> 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

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to