JQuery click function exception
I show a container <div class="expand">that, when clicked, expands sectionbelow it:
HTML:
<div class="expand">
<div class="container1">
<div class="container2">
<a class="view">View</a>
<a class="download">Download</a>
</div>
</div>
</div>
<section class="hidden">
...
</section>
JQuery
$('.expand').click(function () {
var $this = $(this);
$this.next().show();
});
As you can see, <div class="expand">there is a Download button as a child . This download button should be the only element in this container itself that does not start the specified section to be displayed.
So, I would like to do something like this:
$('.expand').not(".download").click(function () {
...
});
or
$('.expand').except(".download").click(function () {
...
});
+4
5 answers
You can also use event.stopPropagation () :
$('.download').click(function(event) {
event.stopPropagation();
}
$('.expand').click(function () {
...
});
DOM .
+5