$(".toggle-more-less").click(function() {
$(this).closest(".article").toggleClass("show-hide");
});
I am trying to toggle article length for a smartphone size site to save space.
I thought that this would work – but I don’t understand .closest() I guess.
HERE is a jsfiddle.
Any direction would be GRRRRREAT!
$(this) means the items that initiated the function, so in this case ‘$(“.toggle-more-less”)’.
Closest will look for the closest parent to $(this) that fits the set criteria, so in this case it will traverses the dom upwards until it reaches a ‘figure’.
Fiddle: http://jsfiddle.net/6whzQ/