The following code is working exactly as it is expected to work, the thing is that I'm sure that it can be written in a more efficient and less verbose way, any reviews?
JavaScript:
$(document).ready(function() {
$('.hidden-content').hide();
$(".hidden-content-reveal").click(function() {
var $i = $(this).children();
if ($i.is(".angle-down")){
$i.removeClass("angle-down");
$i.addClass("angle-up");
} else {
$i.removeClass("angle-up");
$i.addClass("angle-down");
}
return false;
});
});
HTML:
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<a href="#" class="hidden-content-reveal">
<i class="angle-down" style="font-size:24px"></i>
</a>
<div class="hidden-content">
<p>Nulla facilisi. Cras non egestas lectus. Duis malesuada eleifend neque, eget tincidunt elit convallis sed.Nulla facilisi. Cras non egestas lectus.</p>
</div>
</div>
.toggleClass()
for example? api.jquery.com/toggleclass \$\endgroup\$.toggleClass()
is working, but the "trick" is that I had to target both classes like that:toggleClass("angle-down angle-up")
. Post your comment as an answer so to be able to accept it. \$\endgroup\$