简体   繁体   中英

How do I change a label text when that particular label is selected using jQuery?

I want to update every single label I generate by using the #updatelabel input only. Let's say, I generate 3 textboxes along with labels (with incremental id) and I just would like to change the label #2 then how would I do that? Because if I choose to update label #2 then the only one that updates is label #1 and after that I can't update any other label.

Here is a demo http://jsfiddle.net/H9mKZ/

I really need a good answer. Thanks.

Only one element is allowed to have an ID at a time. Instead of $("#updatelabel") you should use a class $(".updatelabel") .

While tandu is correct about the ID property, you can always store a reference to the text box that was clicked and just you that to get the value. Here is an updated example: http://jsfiddle.net/H9mKZ/1/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM