addID in jQuery?

eozzy picture eozzy · Nov 1, 2009 · Viewed 195.5k times · Source

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

Answer

Christian C. Salvadó picture Christian C. Salvadó · Nov 1, 2009

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.