Raising an event when anything is clicked except an element

时间:2015-07-28 15:55:03

标签: javascript jquery html

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?

1 个答案:

答案 0 :(得分:6)

Use event.target

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