javascript - Is it possible to set ID and Class of an element using jQuery method attr()? -


$("selector").attr("id","idname"); 

is possible use above setting id or class of element.

hm feel i've said thousands of times. jquery class selector returns array of html elements class. so, if want data form elements need loop on array or access directly.

$('.gg1').first().attr("id"); //returns id of first element class gg1 $('.gg1')[1].attr("id"); //returns id of second element class gg1  for(var = 0; < $('.gg1').legth; i++= {   console.log($('.gg1')[i]); } //loops on cormplete html collection 

http://api.jquery.com/attr/

http://www.google.com


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -