On my blog theme i have a "SHOW MORE POST" button after the last post of the page. When the user clicks the button, more posts are loaded without refreshing the page. I am doing this using the "Ajax Load More" plugin from the Wordpress repository. When there are no more post to load, i would like to hide this button.
When there are no more posts, the button becomes a class of ".done", added by ajax.
i have been trying to hide the button using jQuery like this:
jQuery(document).ready(function($) {
var morebutton = $("button#load-more");
if ( $(morebutton).hasClass("done") ) {
$(this).hide();
}
});
but i am having no result. I think i have the right selectors. i have tryed to hide it on a click and it works. i used this jquery:
jQuery(document).ready(function($) {
var morebutton = $("button#load-more");
$(morebutton).click(function(){
if ( $(this).hasClass("done") ) {
$(this).hide();
}
});
});
So, my question is how can i check if an element hasClass, if this class is dynamically added with AJAX?
When i use the document.ready function it will check my element only on document.ready. Is this correct? So how could i check also after an ajax event?
Any other ways to hide the button after all posts are loaded?
Thank you!
Aucun commentaire:
Enregistrer un commentaire