Skip to content
Advertisement

jquery select change get data attribute value for each tr td in The table contains dynamically generated rows

I’ve created a table with two rows, with the ability to create additional rows dynamically; the problem I’m having is that I want to make the value of the last cell in any row related to the user’s choice from the drop-down list in the first cell in the row.

I have code that works, but it only works on the first row correctly and repeats printing the same value in all next rows, any good suggestion would be appreciated and thank you;

my problem is here:

JavaScript

html code :

JavaScript

Advertisement

Answer

instead of id use class as you can use 1 id only once in a particular page. so your code would be:

JavaScript

closest will find your nearest tr to your select button inside which it will find element with mount class and update value there

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