domino
domino

Reputation: 7345

jquery not() not working as expected

<div class="row">
<img src="images/image.png" width="30" height="30" alt=""/>
<a href="#">View</a>
</div>


$(".row").not(".row a").click(function(){

             // irrelevant
        })

I can't figure out why this isn't working. I don't want to call the function when "View" is clicked.

Upvotes: 0

Views: 63

Answers (2)

Hadas
Hadas

Reputation: 10374

Use this:

 $(".row").click(function(){

 });


$('.row a').click(function(e){
      e.stopPropagation();   //this cancel the other events 
});

Upvotes: 1

Engineer
Engineer

Reputation: 48793

Is this ,what you were looking for?

$(".row").on('click',':not(a)', function(){
});

Adds 'click' event listener on all child elements of '.row', except 'a' elements.

Upvotes: 2

Related Questions