Hi and welcome to jQuery :]

A simple but not very effective way to do that is $
('#myelement').parents('body').length, or, if you are sure you're
dealing with a single element, a check for $('#myel')[0].parentNode
would suffice.

You can also implement this as a plug-in:

jQuery.fn.inDOM = function(){
  var d = false,
  m = (document.contains)
     ? function(){ return (d = document.contains(this)) }
     : function(){ return (d = !!(document.compareDocumentPosition
(this) & 16)) }

   this.each(m);
   return d;
};

(there was a lengthy discussion about this at jquery-dev:
http://groups.google.com/group/jquery-dev/browse_thread/thread/ac5ca8eaa64fe9f1/af83ebdd79de479a)

jQuery has a few helper functions for strings, arrays, etc:
http://docs.jquery.com/Utilities. I have yet to find something I can't
do with it :)

cheers,
- ricardo

On Feb 4, 9:29 am, Bisbo <cappuccinof...@googlemail.com> wrote:
> Hi there,
>
> I'm a recent converter from Prototype to jQuery and I've got a couple
> of questions.
>
> Firstly, if I am storing a jQuery object containing an element (var el
> = $('#myelement');) and then I subsequently remove that element ($
> ('#myelement').remove()), how can I test my el variable to see if that
> element exists in the document or has been removed? I cannot simply
> test using the id of the element as I I'm storing tens of elements
> this way and it's not practical. It would appear that the jQuery
> object is still holding a reference to the removed element and hence
> any checks for it on the object return as okay.
>
> Secondly, I'm having some withdrawal symptoms from Prototype and I'm
> missing the many other functions such as it's String, Array, Object
> and even some of it's Element functions. I did think about using both
> libraries as the same time but that would be a hefty download. Are
> there any other options that anyone is using, perhaps some good
> plugins or other smaller libraries the do the job nicely?
>
> Many thanks,
>
> Michael

Reply via email to