Reputation: 1610
I have:
<label for="gender" class="error">Choose</label>
I would like to add an id to this line via jQuery/javascript so the html would end up like:
<label for="gender" class="error" id="addthisid">Choose</label>
Is it possible? How can I do that?
Upvotes: 1
Views: 1745
Reputation: 1677
I am guessing you are trying to do that with jQuery. So here we go.
$(function(){
$('label').attr('id', 'addthisid');
});
Here is an example: http://jsfiddle.net/peduarte/RkCLR/
Upvotes: 0
Reputation: 342775
Like this:
$("label[for='gender']").attr("id", "addthisid");
or:
$("label[for='gender']")[0].id = "addthisid";
or:
$("label[for='gender']").get(0).id = "addthisid";
Upvotes: 2