Skip to content
Advertisement

Why my load more button won’t work whatever I do?

I’ve been struggling with this the whole day, I just can’t get it working for I don’t know which reason. The doubt is because I have another section on the same page and it works perfectly.

I have a form, and when that form gets submitted I show results below without refresh with the help of AJAX. Now at the bottom I have a Load More button which should calculate all outputted results and limit them to 3. So when the Load More button is clicked it will show 3 more results and so on.

My PHP + HTML:

JavaScript

jQuery (Updated):

JavaScript

So the PHP code gets all the rows from the selected column/table, that works great, with the AJAX I show submitted comments bellow, which works great too. But the Load more button doesn’t do nothing when its clicked. The script shows only three divs and hide others, but when clicked it doesn’t respond. The $post_inc2 and the $increase variables increases the number on the divs (because I have multiple feeds that lets you comment on it).

Any help will mean a lot, since I’m really frustrated.

Advertisement

Answer

A few pointers:

  1. Oftentimes .show() won’t do anything unless you do .hide() first, and vise versa. You can chain them, e.g. $(el).hide().show() … it’s probably this.
  2. Otherwise make sure your selectors are working by assigning your $('selector') calls to a variable and then doing a console.log(thatVar.length) to make sure each of them got the number of results you expected.
  3. Finally it’s possible you are attempting to attach your click listener before the element is ready in DOM. Best practice is always to attach listeners either inline or (in your case) during a DOM ready event:
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement