The general idea of the code is that I have a +
or -
icon (".trigger"
) that is click-able and will expand or collapse the content (".cont"
) directly following it (there are many of there expand/collapse pairs). I also have a span
("#expandAll"
) that, when clicked, will expand or collapse every block.
Please review my first usage of jQuery and help me put my head into a more jQuery state. Where can the code be improved? Are there any problems with it? Is there a better way to do it?
(To be perfectly honest, I have no idea what the $()
function really does.)
var expandAll = function () {
$(".cont").removeClass("hid");
$("#expandAll").html("Colapse All");
$("#expandAll").unbind("click", expandAll);
$(".trigger").html("-");
$("#expandAll").click(colapseAll);
}
var colapseAll = function () {
$(".cont").addClass("hid");
$("#expandAll").html("Expand All");
$("#expandAll").unbind("click", colapseAll);
$(".trigger").html("+");
$("#expandAll").click(expandAll);
}
$(document).ready(function () {
$(".trigger").click(function (event) {
$this = $(this);
$this.html($this.text() == '+' ? '-' : '+');
$($this.nextAll(".cont").get(0)).toggleClass("hid");
});
$("#expandAll").click(expandAll);
});
Please let me know if you need more/less info.