Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to animate dynamically created collapsible sets in jQuery Mobile
    primarykey
    data
    text
    <p>I'm currently creating an application that receives data from a server and then dynamically creates collapsible elements. Now I have code that allows for the animation of the opening and closing of the collapsible elements across the whole application:</p> <pre><code>$('[data-role="collapsible"]').bind('expand', function () { $(this).children().slideDown(500); }).bind('collapse', function () { $(this).children().next().slideUp(500); }); </code></pre> <p>Now this code doesn't work on the dynamically created collapsible elements. Thus what I have tried to do is the following:</p> <pre><code>$(document).on('pagechange','#resultssearch', function() { $('[data-role="collapsible"]').bind('expand', function () { $(this).children().slideDown(500); }).bind('collapse', function () { $(this).children().next().slideUp(500); }); }); </code></pre> <p>So on the page where the dynamic collapsible elements are added to I tried to add the above page event. But some how this also doesn't seem to work. How would I get dynamically generated to animate? </p> <p>As shown in the suggested answers the code that works is given as:</p> <pre><code>$(document).on('expand', '[data-role="collapsible"]', function () { $(this).children().slideDown(500); }).on('collapse', '[data-role="collapsible"]', function () { $(this).children().next().slideUp(500); }); </code></pre> <p>How ever this doesn't work 100%. The events of children collapsibles end up affecting the parent collapsibles, this can be seen <a href="http://jsfiddle.net/CphEb/" rel="nofollow">here</a>. Is there any way of stopping the children collapsibles from doing this?</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