Home > database >  jQuery get dynamic id of html element
jQuery get dynamic id of html element

Time:11-24

I want to update text in html element on AJAX post.

Element is in td. Problem is I have many td so I named it id="[email protected]" so every td has binded UserId.

I have this id in variable var someTabId = "someTab." userId

Then I want to update its text on some action. $("#" someTabId).text("some text here")

And its not updating. I used console.log to check if someTabId is equal to its element id and it is

HTML Element I want to update:

<td id="[email protected]">I want to update value here</td>

CodePudding user response:

you can use instead of

var someTabId = "someTab."   userId

to

var someTabId = "someTab_"   userId

it will work.

because "." is a class selector in jQuery.

CodePudding user response:

Since I got no answer I found a workaround.

I just refresh whole table in background by writing $("#someTab").load(location.pathname " #someTab"); in AJAX.

  • Related