Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can trigger a custom event on the newly added DOM element that can be picked-up by a jQuery event handler:</p> <pre><code>//bind to our custom event for the `.sub-element` elements $('#container').on('custom-update', '.sub-element', function(){ $(this).html('&lt;b&gt;yaay!&lt;/b&gt;'); }); //append a new element to the container, //then select it, based on the knowledge that it is the last child of the container element, //and then trigger our custom event on the element $('#container').append('&lt;div class="sub-element"&gt;No worky!&lt;/div&gt;').children().last().trigger('custom-update'); </code></pre> <p>Here is a demo: <a href="http://jsfiddle.net/ggHh7/4/" rel="noreferrer">http://jsfiddle.net/ggHh7/4/</a></p> <p>This method allows you to do something globally even if you load the dynamic content through different methods.</p> <h1>Update</h1> <p>I'm not sure of the browser support (I'll assume IE8 and older don't support this) but you can use the <code>DOMNodeInserted</code> mutation event to detect when a DOM element is added:</p> <pre><code>$('#container').on('DOMNodeInserted', '.sub-element', function(){ $(this).html('&lt;b&gt;yaay!&lt;/b&gt;'); }) $('#container').append('&lt;div class="sub-element"&gt;No worky!&lt;/div&gt;'); </code></pre> <p>Here is a demo: <a href="http://jsfiddle.net/ggHh7/7/" rel="noreferrer">http://jsfiddle.net/ggHh7/7/</a> ​</p> <h1>UPDATE</h1> <p>There is a new API for this as <code>DOMNodeInserted</code> is depreciated at this time. I haven't looked into it but it's called <code>MutationOvserver</code>: <a href="https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver" rel="noreferrer">https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver</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