jQuery HTML Element How to - Remove href from inner div tag for outside anchor








Question

We would like to know how to remove href from inner div tag for outside anchor.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.7.1.js'></script>
<script type='text/javascript'>
$(window).load(function(){<!--from w w  w .  j a v a  2 s. c o  m-->
    $('a').click(function(e){
       console.log(e.target);
       if($(e.target).hasClass('tooltip')){
          return false;
       }
    });
});
</script>
</head>
<body>
  <a href="http://java2s.com">Title
    <div class="tooltip">My text....</div>
  </a>
</body>
</html>

The code above is rendered as follows: