Yes, the code can indeed be condensed by controlling everything with class names rather than ids. Fortunately most of the necessary classes are already in place.
First give both sections an overall div wrapper:
<div class="section">
...
</div> This allows us to set a $section variable in the javascript which will act as a "context" each time an arrow is clicked.
Second, give each of the arrow images a class:
<img .... class="rightArrow" /><!-- twice -->
<img .... class="downArrow" /><!-- twice --> Now, the javascript:
$(document).ready(function() {
$(".longDescription").hide();
$(".afterDropDown").hide();
$(".rightArrow").click(function() {
var $section = $(this).closest(".section");//context for jQuery selectors below
$(".beforeDropDown", $section).hide();
$(".afterDropDown", $section).show();
$(".shortDescription", $section).hide();
$(".longDescription", $section).slideDown("slow");
});
$(".downArrow").click(function() {
var $section = $(this).closest(".section");//context for jQuery selectors below
$(".longDescription", $section).slideUp("slow", function() {
$(".afterDropDown", $section).hide();
$(".beforeDropDown", $section).show();
});
$(".shortDescription", $section).show("slow");
});
});
Untested
Airshow
Airshow
WiFi Lounge Lizard
Moderator
2,682 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372