Question

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?

Was it helpful?

Solution

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

OTHER TIPS

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top