Note that there are some explanatory texts on larger screens.

plurals
  1. POstop event from bubbling up the DOM
    primarykey
    data
    text
    <p>I have an event handler that is being fired on a container document, propagating it to a li-Element down inside itself. For some reason, when I press return, the event also fires for a link a bit further up the DOM tree. I wasn't able to stop the event from bubbling up the DOM and I don't know why. Can anyone help? Thanks.</p> <p>I'm using jQuery 1.7 and unfortunately I can't give live code examples that make any sense due to the complexity of it... :-(</p> <p>My HTML is something like this:</p> <pre><code>&lt;div id="contentBox"&gt; &lt;form [...]&gt; &lt;a class="del" href="javascript:[...]"&gt;Delete entry&lt;/a&gt; &lt;fieldset&gt; &lt;legend&gt;An entry&lt;/legend&gt; &lt;input name="xy" class="lmti"&gt; &lt;ul&gt; &lt;li&gt;Result 1&lt;/li&gt; &lt;li&gt;Result 2&lt;/li&gt; &lt;li&gt;Result ...&lt;/li&gt; &lt;/ul&gt; &lt;/fieldset&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>Pieces of my Javascript look like this:</p> <pre><code>$('#contentBox').on('click', '.del', function(e) { [...deletes an entry...] }); </code></pre> <p>and</p> <pre><code>$('#contentBox').on('keyup', '.lmti', function (e) { [...takes over search results...] }); </code></pre> <p>What happens is this:</p> <p>Contents of <em>#contentBox</em> are dynamically loaded using ajax. I have a list of elements in there, which I can dynamicly expand. Each time I add a new element, a set of all tags within a <em>fieldset</em> is being added. I can delete an element using the link <em>class="del"</em> next to it. When a user types into the input box I dispay a live-search-box below it, so he can take over entries from there. This can also be done by pressing <em>arrow down</em>, going through the search results and then pressing <em>return</em> to take over a result.</p> <p>Within above event I check for a pressed <em>return</em> and I actually take a title from a list of titles and put it in a HTML-input field. Like the google live search.</p> <p>The problem: if I press <em>return</em> to take over a result set the above event is also being fired for the click-event-handler of the delete-link.</p> <p>I wasn't able to stop propagation with any combination of <em>e.stopPropagation</em>, <em>e.stopImmediatePropagation</em>, <em>e.preventDefault()</em> and so on.</p> <p>I only found that checking the event-target within the delete-link event-handler stops the entry from being deleted. But I'd prefer the event not to reach the <em>a</em>-click event.</p> <p>%-/</p> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    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. 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