[Solved] Get certain attribute of all anchors of certain class [closed]


use class selector . and prop() to get the attribute.. attr() if you are using old version of jquery (prior jquery 1.6)
try this…

$('.className').prop('name'); //calssName is the name of your class

for multiple elements

$('.className').each(function(){
   console.log($(this).prop('name')) 
});

OR using map()

 var nameArray= $('.class').map(function(){
   return this.name;
 }).get();

 console.log(nameArray);  //nameArray is an array with all the names

fiddle usign map

example..

<a name="test" class="class">test</a>

alert($('.class').prop('name'));

4

solved Get certain attribute of all anchors of certain class [closed]