Monday, January 11, 2016

click on box, but not a link in the box, jquery



I have link inside a box
<div class='term'><a href='#'' class='link'>My Link</a></div>
I have click on class term. When I click the link, I want the class 'term' not trigger a click.
used:
              if (event.target.nodeName == 'A') 
Example:
            $('.term').on('click',  function(event){
              if (event.target.nodeName == 'A') return true;

          } 
 Another method:
 e.stopPropagation();
Example 
$('.term a').click( function(e) {
    e.stopPropagation();
});
Reference:
http://stackoverflow.com/questions/3838758/select-the-div-but-not-the-link-inside-it-jquery-question 

No comments:

Post a Comment