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

Is it possible to use above for setting ID or Class of an element.

RevanthKrishnaKumar V.
  • 1,779
  • 1
  • 19
  • 33
Raghul Rajendran
  • 456
  • 2
  • 6
  • 23

1 Answers1

-1

hm i feel like i've said it thousands of times. The jQuery class selector returns an array of all HTML elements with that class. So, if you want to get data form those elements you need to loop over the array or access it directly.

$('.gg1').first().attr("id"); //returns the id of the first element with class gg1
$('.gg1')[1].attr("id"); //returns the id of the second element with class gg1

for(var i = 0; i < $('.gg1').legth; i++= {
  console.log($('.gg1')[i]); } //loops over the cormplete HTML Collection

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

http://www.google.com

messerbill
  • 4,582
  • 1
  • 19
  • 33