AddID In JQuery?


Answer :

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.


do you mean a method?

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

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


Like this :

var id = $('div.foo').attr('id'); $('div.foo').attr('id', id + ' id_adding'); 
  1. get actual ID
  2. put actuel ID and add the new one

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable