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

java - HTTP Status 500 - An exception occurred processing JSP page /second.jsp at line 15 -

php - Using str_replace to translate a MySQL Table in html -

asp.net mvc - Cannot display error message on Editor or EditorFor -