Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use the <a href="http://api.jquery.com/event.stopPropagation/" rel="nofollow">stopPropagation()</a> method on the event object.</p> <p>It will prevent the event from bubbling up without cancelling the default event behavior.</p> <pre><code>$(document).ready(function () { $("tr").click(function(){ alert("TR"); }); $("input").click(function(e){ alert("INPUT"); e.stopPropagation(); }); }); </code></pre> <hr> <p>As it seems you are using .live() and not direct event binding, you can't use stopPropagation().</p> <p>First of all, <code>.live()</code> is <strong>legagcy code and has been deprecated</strong>, which means it could be removed from the library in any future new version. I don't know which version of jQuery you are using but you should consider moving to the latest (which is more optimized anyway) and use <a href="http://api.jquery.com/on/" rel="nofollow">.on()</a> for event delegation.</p> <p>Nevertheless, if you can't upgrade your jquery library, here's maybe a solution to your problem. The event parameter passed to all event handler contains a property <code>target</code> which reference the element from which the event was initiated. So you could do something like:</p> <pre><code>$("tr").live('click',function(e){ if (e.target.nodeName !== "INPUT") { // if ($(e.target).is('input') === false) { // jquery style but maybe less efficient alert("TR"); } }); </code></pre> <p>Not very elegant but does the trick. Here's an <a href="http://jsfiddle.net/didierg/gcfQT/" rel="nofollow">example</a>.</p> <p>The problem with <code>.live()</code> is that events are binded to the document so as more complex as your application would become, you may end up with headaches to stop propagation.</p> <p>In the meantime I've made a fiddle using <code>.on()</code> (<a href="http://jsfiddle.net/didierg/kJxau/" rel="nofollow">here</a>) and one using <code>.delegate()</code> (<a href="http://jsfiddle.net/didierg/VceJe/" rel="nofollow">here</a>).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload