views:

1814

answers:

2
+1  Q: 

addID in jQuery?

Is there any selector available to add IDs like there is for adding a class - addClass()?

+10  A: 

ID is an attribute, you can set it with the attr function:

$(element).attr('id', 'newID');

I'm not sure what you mean about adding IDs since an element can only have one identifier and this identifier must be unique.

CMS
A: 

do you mean a method?

$('div.foo').attr('id', 'foo123');

Just be careful that you don't set multiple elements to the same ID.

scunliffe