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>
You can use the attribute selector found in jQuery:
$('#r1').find('[data-rating="' + info + '"]')
Reference: List of All jQuery Attribute Selectors
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With