Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
136
rated 0 times [  141] [ 5]  / answers: 1 / hits: 16703  / 10 Years ago, wed, july 23, 2014, 12:00:00

What function can I use to select child div of class=rate_stars.



I have a variable range from 1 - 5 and I want to select child div with that specific data-rating.



I have tried



 $('rate_widget').find().attr('data-rating', info).prevAll().andSelf().addClass('ratings_vote');


But it did't work.



<div id=r1 class=rate_stars
data-post-id=<?php echo $post_id ?>
data-user-id=<?php echo $user_id; ?>
data-nonce=<?php echo $nonce ?>
>
<div data-rating=1 class=ratings_stars></div>
<div data-rating=2 class=ratings_stars></div>
<div data-rating=3 class=ratings_stars></div>
<div data-rating=4 class=ratings_stars></div>
<div data-rating=5 class=ratings_stars></div>
<div class=total_votes>vote data</div>
</div>

More From » jquery

 Answers
33

You can use the attribute selector found in jQuery:



$('#r1').find('[data-rating=' + info + ']')


Reference: List of All jQuery Attribute Selectors


[#70071] Tuesday, July 22, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alanisannettep

Total Points: 695
Total Questions: 96
Total Answers: 91

Location: Australia
Member since Sat, May 27, 2023
1 Year ago
;