user2578819
user2578819

Reputation: 13

Want to fetch class name using php/jquery

I am facing some problem to get the class name of a div. For example my html is like that...

<div class="rating-static rating-48 "></div>
<div class="rating-static rating-40 "></div>

I need to get the value ,for example 48 Don't know if it is possible or not.

Upvotes: 0

Views: 121

Answers (1)

Kartikeya Khosla
Kartikeya Khosla

Reputation: 18873

You can try this :-

$('div.rating-static').each(function(){
  var value = $(this).attr('class').split('-')[2];
  alert(value);
});

Fiddle

OR

$('div.rating-static').each(function(){
    var value = $(this).attr('class').substring($(this).attr('class').lastIndexOf('-') + 1);
    alert(value);
});

Fiddle

Upvotes: 1

Related Questions