Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use <a href="http://api.jquery.com/on" rel="nofollow">on()</a> for <strong>dynamically added elements</strong> like,</p> <pre><code>$('#table_content').on('click',' tr', function () { $('.test').slideUp(0) $(this).append(($('.test')).slideDown('slow')); }); </code></pre> <p><strong>Updated</strong> your <code>div</code> will move to <code>tr</code> which you <code>clicked</code>, so when you <code>click</code> on <code>list</code> it will <code>generate new content</code> in <code>table</code> so your <code>div.test</code> will be removed from <code>HTML</code>, thats why you are not getting the <code>desc div</code> again.</p> <p>To solve this problem you have to add <code>div.desc</code> again in <code>clicking of list</code> like,</p> <pre><code>if(!$('body &gt; div.test').length){ $("body").append('&lt;div class="test"&gt;You slide down a row with content xyz&lt;/div&gt;'); } </code></pre> <p><strong>Full code</strong></p> <pre><code> $('#list').on('click', 'li', function () { var id = this.id; var table_content = ""; // IF id=1,2,3,4,5 Code $("#table_content").html(table_content); // add below code foe div.desc if (!$('body &gt; div.test').length) { $("body").append('&lt;div class="test"&gt;You slide down a row with content xyz&lt;/div&gt;'); } }); </code></pre> <p><a href="http://jsfiddle.net/mS3h4/" rel="nofollow">Demo</a></p> <p><strong>Alternatively,</strong> you can use <a href="http://api.jquery.com/clone" rel="nofollow">clone()</a> like,</p> <pre><code>$(function () { $('#table_content').on('click', 'tr', function () { $clone=$('.test:not(.new-test)').clone();// clone the first test class element $('.new-test').remove();// remove the cloned elements $clone.addClass('new-test').appendTo('body');// add the clone to body $clone.slideUp(0);// playing with clone now $(this).append($clone.slideDown('slow')); }); }); </code></pre> <p><a href="http://jsfiddle.net/mS3h4/1/" rel="nofollow">Working demo</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. 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