Is there any difference between doing this:
$(".topHorzNavLink").click(function() {
var theHoverContainer = $("#hoverContainer");
var thisHorzLink = $(this).attr('linkItem');
if (thisHorzLink == "link2") {
if ($("#hoverContainer").is(":visible") == true) {
$("#hoverContainer").slideUp('slow');
} else {
$("#hoverContainer").slideDown('slow');
}
}
});
or this:
$(".topHorzNavLink").click(function() {
var theHoverContainer = $("#hoverContainer");
var thisHorzLink = $(this).attr('linkItem');
if (thisHorzLink == "link2") {
if (theHoverContainer.is(":visible") == true) {
theHoverContainer.slideUp('slow');
} else {
theHoverContainer.slideDown('slow');
}
}
});
Your second method is more efficient because it runs the selector operation
$("#hoverContainer")only once and uses the same jQuery object over and over rather than run the same selector operation three times and construct three new jQuery objects each time.For compactness and efficiency, you could do this:
Or, if the
linkItemattribute is not dynamically assigned/changed, you could bake it into the selector like this: