I know that this question has been asked many times before, but I can't find a solution excepting of hard-coding the jQuery file... So, I have to show a description when user presses a button and there are multiple descriptions, each with their buttons.
This is what I've done so far...
HTML:
<div id="trDest1" class="trDest">
<!-- Some content here -->
<button class="expandArrow">Show</button>
<button class="closeArrow">Hide</button>
</div>
<div id="trDest1_details" class="details">
<p>show details</p>
</div>
<div id="trDest2" class="trDest">
<!-- Some content here -->
<button class="expandArrow">Show</button>
<button class="closeArrow">Hide</button>
</div>
<div id="trDest2_details" class="details">
<p>show details</p>
</div>
<div id="trDest3" class="trDest">
<!-- Some content here -->
<button class="expandArrow">Show</button>
<button class="closeArrow">Hide</button>
</div>
<div id="trDest3_details" class="details">
<p>show details</p>
</div>
CSS:
.closeArrow {
display: none;
}
.visible-description .expandArrow {
display: none;
}
.visible-description .closeArrow {
display: inline;
}
.visible-description + .trip_details {
display: block;
}
.details {
display: none;
}
jQuery:
// Show/hide Descriptions
$('#trDest1 .expandArrow').click(function(){
$('#trDest1').addClass('visible-description');
$('#trDest1_details').show();
});
$('#trDest1 .closeArrow').click(function(){
$('#trDest1').removeClass('visible-description');
$('#trDest1_details').hide();
});
// Show/hide Descriptions
$('#trDest2 .expandArrow').click(function(){
$('#trDest2').addClass('visible-description');
$('#trDest2_details').show();
});
$('#trDest2 .closeArrow').click(function(){
$('#trDest2').removeClass('visible-description');
$('#trDest2_details').hide();
});
// Show/hide Descriptions
$('#trDest3 .expandArrow').click(function(){
$('#trDest3').addClass('visible-description');
$('#trDest3_details').show();
});
$('#trDest3 .closeArrow').click(function(){
$('#trDest3').removeClass('visible-description');
$('#trDest3_details').hide();
});
As you can see, I wrote a function for each of those divs and I'm wondering if there is another way to clean these functions and add only a function which can do the same...
I can't change the structure of the HTML code.
jsfiddle : https://jsfiddle.net/q84Lnw0y/