Skip to content
Advertisement

Get the correct id according to the div I click

I have the following dynamic code:

JavaScript
JavaScript

This code generates a div with several users and their respective user code. so far so good.

The problem I’m having comes after this step. After returning the users, when I click for example on the user with the user code number 3, it returns the user code 1.

And the correct one, if I click on the user with the code number 3, it should return the user code number 3 and not the 1.

Can you help?

Advertisement

Answer

Here is an example using Event Delegation. You basically check which button it being clicked and get the child input element of its parent instead of the first one available in the document.

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