Pranav Raj
Pranav Raj

Reputation: 873

Raising an event when anything is clicked except an element

I have an html page containing a list of items with an image against each item.

<ul>
  <li>
     <div>
     <div class="text"> Text 1</div>
     <img src="../../Images/Notes.png" class="smallSizeLogo notes"
     </div>
     <div>
     <div class="text"> Text 2</div>
     <img src="../../Images/Notes.png" class="smallSizeLogo notes"
     </div>
  </li>
<\ul>

I want to raise an event if clicked anywhere in the html except the image. Is there a way to do it in jquery?

Upvotes: 2

Views: 46

Answers (1)

AmmarCSE
AmmarCSE

Reputation: 30597

Use event.target

$(document).click(function(event){
    if(event.target.tagName != 'IMG'){
        //code here
    }
});

Upvotes: 6

Related Questions