Skip to content
Advertisement

jQuery not retruning data-id after the first use of the button

I have a php script that creates a table and each id in the table has an edit button. The edit button looks like this.

JavaScript

The number of buttons varies but I am trying to get the data-siteid passed to an ajax call like this.

JavaScript

Its working on the first edit button of the table but it does nothing after that first button. It wont even open the modal.

Advertisement

Answer

The reason is because ID should be unique across your HTML page and it looks like you’re defining multiple elements with the same ID.

So, instead, try adding and using a class selector:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement