I have the following structure in my html:
<div class="parent">
<div class="child"></div>
</div>
I also have two jQuery click()
actions on each of my classes:
$('.parent').click(function() {
//Methods Set 1
});
$('.child').click(function() {
//Methods Set 2
});
Assume that the css is as simple as it need to be, just to be able to click the divs.
Now my question is the following: how is it possible to set the jQuery action in .child
class to execute the Methods Set 2
BUT NOT to execute the Method Set 1
after?
What do I expect to see:
When user click the .parent
class, then it will only execute the first set of methods that belongs in that action call.
When the user click the .child
class, then it will only execute the second set of methods that belongs in that action call.
What happens with my code: when the user click the parent
class, the first set method is called. [OK]
When the user click the .child
class, first the Methods Set 2
is execute, then it calls the Set Method 1
and execute them. [FAIL]
What have I tried so far:
A not so simple question for me that kept me far from many ideas I had and forced me to change my plans so many times.
I have tried to set
.not()
method in my.parent
selector like this:$('.parent').not('.child').click(function() { //Methods Set 1 });
But even if I don't get any errors in my console (I use
firebug
in Firefox for debugging logs) I don't get the expected result.I also tried the
:not()
Selector in my.parent
class but also didn't get the results I expected.$('.parent:not(.child)').click(function() { /*Methods Set 1 */});