0

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.

0

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

@soundhiraraj..you are mistaken ... just check the fiddle link.
i checked sir,it comes last alert as undefined
thanks a lot Kartikeya .it is working :),but is it possible to use the class name,i mean 'rating-static' because in this html there are some other div.
@user2578819..yes .. as you can see in my code i have used $('div.rating-static') as selector which will select only div's with class name rating-static

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.