Skip to content Skip to sidebar Skip to footer

How To Pull The Incrementing Id Of The Elements In The Jquery

The problem is when i try to pull the incrementing id's by using $('#[rowcount].Service_Line').change(function () { as the rown count goes ++ for every loop it's not working can a

Solution 1:

Notice how you use the variable rowcount in a string here:

'[' + rowcount + '].'

And notice how you try to use it in a string here:

"#[rowcount].Service_Line"

See the difference? In the latter example you're not actually using the rowcount variable, you just have a string which contains the literal text "rowcount". Use the variable just like you did in the former example:

"#[" + rowcount + "].Service_Line"

(Repeat this for any other places where you want to use a variable in a string.)

You may even be able to use the somewhat newer template literal syntax:

`#[${rowcount}].Service_Line`

(Note that the syntax highlighting here on Stack Overflow currently doesn't highlight this syntax correctly.)

But in either syntax, the key difference is between using the variable vs. just using a string with the name of the variable.

Post a Comment for "How To Pull The Incrementing Id Of The Elements In The Jquery"