Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery, click element inside clickable element

Tags:

jquery

click

I have HTML syntax as followed :

<table>
  <tr>
    <td id="click1">
      <a href="somelink.html" id="click2">
        here's the link
      </a>
    </td>
  </tr>
</table>

and I have jquery syntax like this

$('td#click1').ajaxify();
$('a#click2').fancybox();

My problem is, if I click the #click2 then the #click1 is selected too.

How can I make it only select #click2 without calling #click1?

like image 836
Bias Tegaralaga Avatar asked Apr 07 '11 07:04

Bias Tegaralaga


1 Answers

$('a#click2').click(function(event){

    event.stopPropagation();

})

you can call stopPropagation, to prevent event bubbling up the DOM tree.

like image 188
Headshota Avatar answered Nov 03 '22 13:11

Headshota