views:

724

answers:

3

I already know how to check elements that are there when the document is ready:

jQuery.fn.exists = function () { 
  return jQuery(this).length > 0; 
}

But this method doesn’t know elements that are added with AJAX. Does anybody know how to do that?

+2  A: 

The method does once the ajax is loaded and appended to the DOM. You could rewrite it a bit:

jQuery.existsin = function (what, where) { 
  return jQuery(where).find(what).length > 0; 
}

The you could on ajax success :

function(data, status){
  if(jQuery.existsin('selector', data)){
    //do foo
  }
}
Eivind
would it be smart to specify "body" as a "default where" ?
Labuschin
thank you! that works for me!
Labuschin
A: 

Maybe this helps: http://plugins.jquery.com/project/livequery/

DASGiB
A: 

can't vote up Eivind's answer b/c i don't have enough rep yet. but it worked perfectly for me w/ ajaxupload... thanks!

helgatheviking