I’m trying to toggle a class for a link when it is clicked so it either shows plus to expand or minus to reduce but I can’t get it working.
My jQuery is as follows:
$(".viewdetails").click(function() {
$(this).toggleClass('viewdetailsoff');
$(this).parents("tr").next().toggle();
return false;
})
My initial link
<a class="viewdetails" title="View History" href="">History</a>
If it’s just the image that isn’t working, make sure
.viewdetailsoffis defined after.viewdetailsin the CSS, like this:Regardless of class order on the element itself, e.g. it’ll be
class="viewdetails viewdetailsoff", the order in the CSS is what determines which one wins. Or, you could toggle both classes, effectively swapping them using.toggleClass()like this: