I have many products being populated dynamically, all with same id and class names. I want each "Buy Now" button to have its own div that toggles with click of button.
I do have the ability to assign an incrementing number index to the ids and classes, however, if there's a way to avoid it, I don't want to manually list each unique id and class to target each click function.
What's the best way to accomplish this?
Here's what I have now...
HTML:
<button class="btn button-success clickme">Buy Now</button>
<div class="book" style="display: none;">
<!-- content here -->
</div>
<button class="btn button-success clickme">Buy Now</button>
<div class="book" style="display: none;">
<!-- content here -->
</div>
jQuery:
$( ".clickme" ).click(function() {
$( ".book" ).slideToggle( "slow", function() {
// Animation complete.
});
});