Reputation: 8568
I have the following HTML:
<label>Lobby Template:</label>
I want to convert it to jquery object and add an attribute id with a value of test:
<label id="test">Lobby Template:</label>
Upvotes: 0
Views: 1318
Reputation: 10764
labels = $('label')
$.each(labels, function(i, label){
if($(label).html() == 'Lobby Template:' ){
$(label).attr("id", "test")
}
})
Upvotes: 0
Reputation: 193261
I like this syntax:
var $el = $("<label>", {
id: "test",
text: "Lobby Template:"
});
Upvotes: 2
Reputation:
$('label')[0].id="test";
You need to have some sort of hook to identify your element. http://jsfiddle.net/RQ3vH/1/ is a demo.
Upvotes: 0