Reputation: 516
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?
Upvotes: 1
Views: 2480
Reputation: 841
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
}
}
Upvotes: 3