Reputation: 8663
What i am trying to achieve is pretty simple. I have a div with an expand/collapse icon and a question mark icon. When a user clicks on one of these icons, the corresponding hidden div's should slide down.
This is working when a user clicks on the expand/collapse icons, but not the question mark.
HTML:
<div class="toggle_head Header">
<label>
<img class="expandCollpse" src="http://png-1.findicons.com/files/icons/2338/reflection/128/expand_alt.png" height="30px;" />
<img class="hide expandCollpse" src="http://png-2.findicons.com/files/icons/2338/reflection/128/collapse_alt.png" height="30px;" />
</label>
<label>Expand</label>
<label class="showHelp">
<img src="http://www.katherineemmons.com/wp-content/uploads/2013/06/question_mark-icon.png" height="30px;" />
</label>
</div>
<div class="toggle_body">
<button type="button" class="btn" style="float:right;">Close</button>
<label>**Info from expand/collapse icon click** - Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco</label>
</div>
<div class="helpBody">
<label>**Info from HELP icon click** - Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco</label>
</div>
jQuery:
$(".toggle_body").hide();
$(".collapse").hide();
$(".helpBody").hide();
$(".toggle_head").click(function () {
var $this = $(this);
$this.next(".toggle_body").slideToggle("slow", function () {
$this.find('img.expandCollpse').toggle();
});
});
$(".showHelp").click(function () {
var $this = $(this);
$this.find('div.helpBody').slideToggle("slow");
});
$(".btn").click(function () {
var $this = $(this);
$this.closest(".toggle_body").slideUp();
})
Here's my fiddle: http://jsfiddle.net/oampz/x7k9B/4/
Any help appreciated.
Upvotes: 0
Views: 316
Reputation: 2094
try this code
<div class="toggle_head Header">
<label id="toggle_head">
<img class="expandCollpse" src="http://png-1.findicons.com/files/icons/2338/reflection/128/expand_alt.png" height="30px;" />
<img class="hide expandCollpse" src="http://png-2.findicons.com/files/icons/2338/reflection/128/collapse_alt.png" height="30px;" />
</label>
<label>Expand</label>
<label class="showHelp">
<img src="http://www.katherineemmons.com/wp-content/uploads/2013/06/question_mark-icon.png" height="30px;" />
</label>
</div>
<div class="toggle_body">
<button type="button" class="btn" style="float:right;">Close</button>
<label>Info from expand/collapse icon click - Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco</label>
</div>
<div class="helpBody">
<label>Info from HELP icon click - Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco</label>
</div>
<script>
$(document).ready(function () {
$(".toggle_body").hide();
$(".collapse").hide();
$(".helpBody").hide();
$("#toggle_head").click(function () {
var $this = $(this);
$(".toggle_body").slideToggle("slow", function () {
$this.find('img.expandCollpse').toggle();
});
});
$(".showHelp").click(function () {
var $this = $(this);
$('.helpBody').slideToggle("slow");
});
$(".btn").click(function () {
var $this = $(this);
$this.closest(".toggle_body").slideUp();
})
});
</script>
Upvotes: 1
Reputation: 26396
here's an updated fiddle with the issue fixed: http://jsfiddle.net/x7k9B/5/
the div was eating the clicks on the help icon.
here's the updated code:
$(".toggle_body").hide();
$(".collapse").hide();
$(".helpBody").hide();
$(".toggle_head").click(function (event) {
var $this = $(this);
// is the click event's target the showHelp label?
if ($(event.target).closest('label').hasClass('showHelp')) {
$(".helpBody").slideToggle("slow", function () {
$this.find('img.expandCollpse').toggle();
});
return;
}
// click event occurred somewhere else on the header div- not on showHelp...
$this.next(".toggle_body").slideToggle("slow", function () {
$this.find('img.expandCollpse').toggle();
});
});
$(".btn").click(function () {
var $this = $(this);
$this.closest(".toggle_body").slideUp();
})
Upvotes: 3