I have 3 div elements on my page and each of them has the same CSS class “.shape”
In my JS, I want to target the current click “.shape”, so some extra html will be inserted at the bottom of the “.shape” with the jQuery slideDown transition.
And when you click on ".shape" again, the additional html will be slideUp.
How can I do this easily? What I have:
$(".shape").click(function() {
var id = $(this).attr("id");
var selected = id + "-reveal";
});
In my HTML
<div class="shape" id="shape1">Content</div>
<div class="hidden" id="shape1-reveal">Content</div>
<div class="shape" id="shape2">Content</div>
<div class="hidden" id="shape2-reveal">Content</div>
<div class="shape" id="shape3">Content</div>
<div class="hidden" id="shape3-reveal">Content</div>
I also don't know how to add a switch / slide effect.
EDIT: Solution
http://codepen.io/vennsoh/pen/rVjeQy
Not sure if the way I wrote my JS is the most elegant approach.
source
share