Dynamically adding collapsible elements












12















Source: http://jquerymobile.com/demos/1.0a2/#docs/content/content-collapsible.html
When I add an element like this manually to my code, it is displayed properly.
But when I try to add it with jQuery like this:



$('body').append('<div data-role="collapsible"><h3>Title</h3><p>Content</p></div>');


It just displays title in h3 and the content below it, so not as a collapsible element.
How can I fix this?










share|improve this question



























    12















    Source: http://jquerymobile.com/demos/1.0a2/#docs/content/content-collapsible.html
    When I add an element like this manually to my code, it is displayed properly.
    But when I try to add it with jQuery like this:



    $('body').append('<div data-role="collapsible"><h3>Title</h3><p>Content</p></div>');


    It just displays title in h3 and the content below it, so not as a collapsible element.
    How can I fix this?










    share|improve this question

























      12












      12








      12


      2






      Source: http://jquerymobile.com/demos/1.0a2/#docs/content/content-collapsible.html
      When I add an element like this manually to my code, it is displayed properly.
      But when I try to add it with jQuery like this:



      $('body').append('<div data-role="collapsible"><h3>Title</h3><p>Content</p></div>');


      It just displays title in h3 and the content below it, so not as a collapsible element.
      How can I fix this?










      share|improve this question














      Source: http://jquerymobile.com/demos/1.0a2/#docs/content/content-collapsible.html
      When I add an element like this manually to my code, it is displayed properly.
      But when I try to add it with jQuery like this:



      $('body').append('<div data-role="collapsible"><h3>Title</h3><p>Content</p></div>');


      It just displays title in h3 and the content below it, so not as a collapsible element.
      How can I fix this?







      jquery mobile






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 18 '10 at 12:05









      BillBill

      61113




      61113
























          11 Answers
          11






          active

          oldest

          votes


















          19














          The easiest way to achieve this is to call the collapsible() method on the dynamically created divs:



          $('div[data-role=collapsible]').collapsible();


          source : http://forum.jquery.com/topic/dynamically-add-collapsible-div






          share|improve this answer
























          • This does not work for me. But calling $('#your_new_collapsible_div').trigger('create') after adding the element to the DOM (as proposed by Amit and Basav) works fine.

            – zitroneneis
            Jun 24 '13 at 18:17





















          4














          this is what i do. Hope it helps



          HTML



          <div id="collapsibleSet" data-role="collapsible-set">
          <div id="ranking1"></div>
          </div>


          Javascript



          $('#ranking1').replaceWith('<div id="ranking1" data-role="collapsible" data-collapsed="false">' + htmlRankings(ranking) + '</div>');
          $('#collapsibleSet').find('div[data-role=collapsible]').collapsible({refresh:true});


          htmlRankings() is a js function that returns some html that i want inside the collapsible div.
          it can be something like this



          <h3>11</h3>
          <span>test</span>





          share|improve this answer































            4














            I think



            after setting the innerhtml, simply tiggerring a event on it should render the dynamic contnet like below



            $('#<divId or elementId').trigger("create");





            share|improve this answer































              2














              This code is for perl, you can modify it for any programming language.



               <a href="javascript:collapsible('$div_instance','$imageID')">
              <IMG id='$imageID' SRC='$imagePath' alt='(Expand / Collaspe Section' title='Expand / Collaspe' width=10 height=10>
              $display_header <br/></a>
              <div id=$div_instance name=$div_instance
              style="overflow:hidden;display:$display_option;margin-left:30px; margin-top:20px;">
              <-- your content -->
              </div>
              <script language="JavaScript" type="text/javascript">
              <!--
              function collapsible(theID,imageID) {
              var elemnt = document.getElementById(theID);
              var imageObject =document.getElementById(imageID);
              if(elemnt.style.display == 'block') {
              elemnt.style.display ='none';
              imageObject.src='images/expand_icon.gif';
              }
              else{
              elemnt.style.display ='block';
              imageObject.src='images/expand_icon_down.gif';
              }

              }
              // -->
              </script>


              REF: http://www.ssiddique.info/simple-javascript-to-create-dynamic-collapsible-section.html






              share|improve this answer































                1














                As of jquery mobile beta2 you trigger an event - .trigger('create')






                share|improve this answer































                  1














                  you can refresh the collapsible using the following code



                  $('#element').collapsibleset('refresh');


                  Hope it helps






                  share|improve this answer































                    0














                    You have to append them to the right place (e.g. under a data-role="page" element) then call .page() to initialize the content you appended, like this:



                    $('<div data-role="collapsible"><h3>Title</h3><p>Content</p></div>')
                    .appendTo('#someElement').page();


                    You can test it out here.






                    share|improve this answer
























                    • very nice code - thank you.... followup question, how would you turn the two items into a single seamless item?

                      – pithhelmet
                      Oct 10 '12 at 20:17











                    • @pithhelmet - not sure I understand what you're asking to do, can you clarify a bit?

                      – Nick Craver
                      Oct 10 '12 at 21:34











                    • sure - your example shows two distinct items, i'm a header and title... they are separated by a space... is there a way to smash those two items into a seamless box... like this jquerymobile.com/demos/1.0rc3/docs/content/…

                      – pithhelmet
                      Oct 10 '12 at 21:50











                    • @pithhelmet - just needed a newer version of jquery UI than the fiddle above was using, is this what you're after? jsfiddle.net/TYscV/566 (ignore the missing icons...seems to be an issue with jsfiddle including the CDN CSS)

                      – Nick Craver
                      Oct 10 '12 at 22:13



















                    0














                    Better than collapsible is updatelayout, it is in the docs. In short...




                    This event is triggered by components within the framework that dynamically show/hide content, and is meant as a generic mechanism to notify other components that they may need to update their size or position. Within the framework, this event is fired on the component element whose content was shown/hidden, and bubbles all the way up to the document element.




                    $('div[data-role=collapsible]')
                    .trigger( 'updatelayout' );
                    //.collapsible();





                    share|improve this answer































                      0














                      This way you can add small collapsibles in a bigger one dynamically.
                      HTML:



                      <div data-role="collapsible" data-mini="false" data-theme="b"  >
                      <h3>main header text</h3>
                      <div id="aCollaps"></div>
                      </div>


                      Javascript



                      //Your could do for(){
                      $("#aCollaps").append('<div data-role="collapsible" data-inset="false" data-content-theme="b">' +
                      '<h3>'+HeaderText+'</h3>'+ContentText+'<br/></div>');
                      //}
                      //You might want to be more specific here if you have more collapsibles in the page. this just updates all collapsibles
                      $('div[data-role=collapsible]').collapsible({refresh:true});





                      share|improve this answer































                        0














                        Here's an example of what I did to dynamically change my collapsible. I had a few arrays that I needed to display as headers, and then I needed a grid in each collapsible set with 2 sides, one for question and one for answer.



                           var inputList = '';
                        var count = 0;
                        var divnum = 999;
                        var collit = 'false';
                        inputList += '<div data-role="content">';
                        inputList += '<div id="fb_showings_collapse" data-role="collapsible-set" data-theme="b">';
                        $.each(fbFullStrArray, function(index, item) {
                        //set questions and answers for each appt
                        getsetApptFback(fbStrApptArray[index]);
                        //write the html to append when done
                        inputList += '<div data-role="collapsible" data-collapsed="'+collit+'">';
                        inputList += '<h3>'+fbFullStrArray[index]+'</h3>';
                        inputList += '<div id="g'+divnum+'" class="ui-grid-a">';
                        inputList += '<div id="gb'+divnum+'" class="ui-block-a">';
                        inputList += '<div id="fbq'+index+'"><ol>';
                        $.each(fbQidArray, function(ind,it) {
                        inputList += '<li>'+fbQuestionArray[ind]+'<b></b></li>';
                        });
                        inputList += '</ol></div></div>'
                        inputList += '<div id="ga'+divnum+'" class="ui-block-b">';
                        inputList += '<div id="fba'+index+'"><ul>';
                        $.each(fbQidArray, function(ind,it){
                        inputList += '<li>'+fbAnswerArray[ind]+'<b></b></li>';
                        });
                        inputList += '</ul></div></div></div></div>';
                        collit = "true";
                        divnum++;
                        count++;
                        });
                        inputList += '</div></div>';

                        $('#fb_showings_collapse [role=collapsible-set]').text('');
                        $('#fb_showings_collapse [role=collapsible]').text('');
                        if (count > 0) {
                        $('#fb_showings_collapse [role=collapsible]').remove();
                        $('#fb_showings_collapse').append(inputList).collapsibleset('refresh');
                        }
                        else if (count == 0){
                        inputList = 'Sorry! No Showings To Show Feedback For!';
                        $('#fb_showings_collapse [role=collapsible-set').remove();
                        $('#fb_showings_collapse [role=collapsible]').text(inputList);
                        }





                        share|improve this answer































                          0














                          See the enhanceWithin() function: jQuery Mobile docs: enhanceWithin



                          Call enhanceWithin on a jQuery object representing your DOM element's parent to have any jQuery Mobile features added to your HTML.



                          In this case:



                          jQuery('[data-role="collapsible"]').parent().enhanceWithin();


                          Note that if you are adding multiple jQuery Mobile widgets you may only want to call enhanceWithin on an ancestor such as "BODY" after adding all your dynamic HTML.



                          This would be a pretty good solution for this question as well: Refresh a section after adding HTML dynamically to jquery mobile






                          share|improve this answer

























                            Your Answer






                            StackExchange.ifUsing("editor", function () {
                            StackExchange.using("externalEditor", function () {
                            StackExchange.using("snippets", function () {
                            StackExchange.snippets.init();
                            });
                            });
                            }, "code-snippets");

                            StackExchange.ready(function() {
                            var channelOptions = {
                            tags: "".split(" "),
                            id: "1"
                            };
                            initTagRenderer("".split(" "), "".split(" "), channelOptions);

                            StackExchange.using("externalEditor", function() {
                            // Have to fire editor after snippets, if snippets enabled
                            if (StackExchange.settings.snippets.snippetsEnabled) {
                            StackExchange.using("snippets", function() {
                            createEditor();
                            });
                            }
                            else {
                            createEditor();
                            }
                            });

                            function createEditor() {
                            StackExchange.prepareEditor({
                            heartbeatType: 'answer',
                            autoActivateHeartbeat: false,
                            convertImagesToLinks: true,
                            noModals: true,
                            showLowRepImageUploadWarning: true,
                            reputationToPostImages: 10,
                            bindNavPrevention: true,
                            postfix: "",
                            imageUploader: {
                            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                            allowUrls: true
                            },
                            onDemand: true,
                            discardSelector: ".discard-answer"
                            ,immediatelyShowMarkdownHelp:true
                            });


                            }
                            });














                            draft saved

                            draft discarded


















                            StackExchange.ready(
                            function () {
                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4214538%2fdynamically-adding-collapsible-elements%23new-answer', 'question_page');
                            }
                            );

                            Post as a guest















                            Required, but never shown

























                            11 Answers
                            11






                            active

                            oldest

                            votes








                            11 Answers
                            11






                            active

                            oldest

                            votes









                            active

                            oldest

                            votes






                            active

                            oldest

                            votes









                            19














                            The easiest way to achieve this is to call the collapsible() method on the dynamically created divs:



                            $('div[data-role=collapsible]').collapsible();


                            source : http://forum.jquery.com/topic/dynamically-add-collapsible-div






                            share|improve this answer
























                            • This does not work for me. But calling $('#your_new_collapsible_div').trigger('create') after adding the element to the DOM (as proposed by Amit and Basav) works fine.

                              – zitroneneis
                              Jun 24 '13 at 18:17


















                            19














                            The easiest way to achieve this is to call the collapsible() method on the dynamically created divs:



                            $('div[data-role=collapsible]').collapsible();


                            source : http://forum.jquery.com/topic/dynamically-add-collapsible-div






                            share|improve this answer
























                            • This does not work for me. But calling $('#your_new_collapsible_div').trigger('create') after adding the element to the DOM (as proposed by Amit and Basav) works fine.

                              – zitroneneis
                              Jun 24 '13 at 18:17
















                            19












                            19








                            19







                            The easiest way to achieve this is to call the collapsible() method on the dynamically created divs:



                            $('div[data-role=collapsible]').collapsible();


                            source : http://forum.jquery.com/topic/dynamically-add-collapsible-div






                            share|improve this answer













                            The easiest way to achieve this is to call the collapsible() method on the dynamically created divs:



                            $('div[data-role=collapsible]').collapsible();


                            source : http://forum.jquery.com/topic/dynamically-add-collapsible-div







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered May 12 '11 at 17:58









                            ozeebeeozeebee

                            1,10811520




                            1,10811520













                            • This does not work for me. But calling $('#your_new_collapsible_div').trigger('create') after adding the element to the DOM (as proposed by Amit and Basav) works fine.

                              – zitroneneis
                              Jun 24 '13 at 18:17





















                            • This does not work for me. But calling $('#your_new_collapsible_div').trigger('create') after adding the element to the DOM (as proposed by Amit and Basav) works fine.

                              – zitroneneis
                              Jun 24 '13 at 18:17



















                            This does not work for me. But calling $('#your_new_collapsible_div').trigger('create') after adding the element to the DOM (as proposed by Amit and Basav) works fine.

                            – zitroneneis
                            Jun 24 '13 at 18:17







                            This does not work for me. But calling $('#your_new_collapsible_div').trigger('create') after adding the element to the DOM (as proposed by Amit and Basav) works fine.

                            – zitroneneis
                            Jun 24 '13 at 18:17















                            4














                            this is what i do. Hope it helps



                            HTML



                            <div id="collapsibleSet" data-role="collapsible-set">
                            <div id="ranking1"></div>
                            </div>


                            Javascript



                            $('#ranking1').replaceWith('<div id="ranking1" data-role="collapsible" data-collapsed="false">' + htmlRankings(ranking) + '</div>');
                            $('#collapsibleSet').find('div[data-role=collapsible]').collapsible({refresh:true});


                            htmlRankings() is a js function that returns some html that i want inside the collapsible div.
                            it can be something like this



                            <h3>11</h3>
                            <span>test</span>





                            share|improve this answer




























                              4














                              this is what i do. Hope it helps



                              HTML



                              <div id="collapsibleSet" data-role="collapsible-set">
                              <div id="ranking1"></div>
                              </div>


                              Javascript



                              $('#ranking1').replaceWith('<div id="ranking1" data-role="collapsible" data-collapsed="false">' + htmlRankings(ranking) + '</div>');
                              $('#collapsibleSet').find('div[data-role=collapsible]').collapsible({refresh:true});


                              htmlRankings() is a js function that returns some html that i want inside the collapsible div.
                              it can be something like this



                              <h3>11</h3>
                              <span>test</span>





                              share|improve this answer


























                                4












                                4








                                4







                                this is what i do. Hope it helps



                                HTML



                                <div id="collapsibleSet" data-role="collapsible-set">
                                <div id="ranking1"></div>
                                </div>


                                Javascript



                                $('#ranking1').replaceWith('<div id="ranking1" data-role="collapsible" data-collapsed="false">' + htmlRankings(ranking) + '</div>');
                                $('#collapsibleSet').find('div[data-role=collapsible]').collapsible({refresh:true});


                                htmlRankings() is a js function that returns some html that i want inside the collapsible div.
                                it can be something like this



                                <h3>11</h3>
                                <span>test</span>





                                share|improve this answer













                                this is what i do. Hope it helps



                                HTML



                                <div id="collapsibleSet" data-role="collapsible-set">
                                <div id="ranking1"></div>
                                </div>


                                Javascript



                                $('#ranking1').replaceWith('<div id="ranking1" data-role="collapsible" data-collapsed="false">' + htmlRankings(ranking) + '</div>');
                                $('#collapsibleSet').find('div[data-role=collapsible]').collapsible({refresh:true});


                                htmlRankings() is a js function that returns some html that i want inside the collapsible div.
                                it can be something like this



                                <h3>11</h3>
                                <span>test</span>






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Aug 7 '12 at 19:22









                                Pablo JohnsonPablo Johnson

                                672920




                                672920























                                    4














                                    I think



                                    after setting the innerhtml, simply tiggerring a event on it should render the dynamic contnet like below



                                    $('#<divId or elementId').trigger("create");





                                    share|improve this answer




























                                      4














                                      I think



                                      after setting the innerhtml, simply tiggerring a event on it should render the dynamic contnet like below



                                      $('#<divId or elementId').trigger("create");





                                      share|improve this answer


























                                        4












                                        4








                                        4







                                        I think



                                        after setting the innerhtml, simply tiggerring a event on it should render the dynamic contnet like below



                                        $('#<divId or elementId').trigger("create");





                                        share|improve this answer













                                        I think



                                        after setting the innerhtml, simply tiggerring a event on it should render the dynamic contnet like below



                                        $('#<divId or elementId').trigger("create");






                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Jun 5 '13 at 19:05









                                        BasavBasav

                                        1,87011217




                                        1,87011217























                                            2














                                            This code is for perl, you can modify it for any programming language.



                                             <a href="javascript:collapsible('$div_instance','$imageID')">
                                            <IMG id='$imageID' SRC='$imagePath' alt='(Expand / Collaspe Section' title='Expand / Collaspe' width=10 height=10>
                                            $display_header <br/></a>
                                            <div id=$div_instance name=$div_instance
                                            style="overflow:hidden;display:$display_option;margin-left:30px; margin-top:20px;">
                                            <-- your content -->
                                            </div>
                                            <script language="JavaScript" type="text/javascript">
                                            <!--
                                            function collapsible(theID,imageID) {
                                            var elemnt = document.getElementById(theID);
                                            var imageObject =document.getElementById(imageID);
                                            if(elemnt.style.display == 'block') {
                                            elemnt.style.display ='none';
                                            imageObject.src='images/expand_icon.gif';
                                            }
                                            else{
                                            elemnt.style.display ='block';
                                            imageObject.src='images/expand_icon_down.gif';
                                            }

                                            }
                                            // -->
                                            </script>


                                            REF: http://www.ssiddique.info/simple-javascript-to-create-dynamic-collapsible-section.html






                                            share|improve this answer




























                                              2














                                              This code is for perl, you can modify it for any programming language.



                                               <a href="javascript:collapsible('$div_instance','$imageID')">
                                              <IMG id='$imageID' SRC='$imagePath' alt='(Expand / Collaspe Section' title='Expand / Collaspe' width=10 height=10>
                                              $display_header <br/></a>
                                              <div id=$div_instance name=$div_instance
                                              style="overflow:hidden;display:$display_option;margin-left:30px; margin-top:20px;">
                                              <-- your content -->
                                              </div>
                                              <script language="JavaScript" type="text/javascript">
                                              <!--
                                              function collapsible(theID,imageID) {
                                              var elemnt = document.getElementById(theID);
                                              var imageObject =document.getElementById(imageID);
                                              if(elemnt.style.display == 'block') {
                                              elemnt.style.display ='none';
                                              imageObject.src='images/expand_icon.gif';
                                              }
                                              else{
                                              elemnt.style.display ='block';
                                              imageObject.src='images/expand_icon_down.gif';
                                              }

                                              }
                                              // -->
                                              </script>


                                              REF: http://www.ssiddique.info/simple-javascript-to-create-dynamic-collapsible-section.html






                                              share|improve this answer


























                                                2












                                                2








                                                2







                                                This code is for perl, you can modify it for any programming language.



                                                 <a href="javascript:collapsible('$div_instance','$imageID')">
                                                <IMG id='$imageID' SRC='$imagePath' alt='(Expand / Collaspe Section' title='Expand / Collaspe' width=10 height=10>
                                                $display_header <br/></a>
                                                <div id=$div_instance name=$div_instance
                                                style="overflow:hidden;display:$display_option;margin-left:30px; margin-top:20px;">
                                                <-- your content -->
                                                </div>
                                                <script language="JavaScript" type="text/javascript">
                                                <!--
                                                function collapsible(theID,imageID) {
                                                var elemnt = document.getElementById(theID);
                                                var imageObject =document.getElementById(imageID);
                                                if(elemnt.style.display == 'block') {
                                                elemnt.style.display ='none';
                                                imageObject.src='images/expand_icon.gif';
                                                }
                                                else{
                                                elemnt.style.display ='block';
                                                imageObject.src='images/expand_icon_down.gif';
                                                }

                                                }
                                                // -->
                                                </script>


                                                REF: http://www.ssiddique.info/simple-javascript-to-create-dynamic-collapsible-section.html






                                                share|improve this answer













                                                This code is for perl, you can modify it for any programming language.



                                                 <a href="javascript:collapsible('$div_instance','$imageID')">
                                                <IMG id='$imageID' SRC='$imagePath' alt='(Expand / Collaspe Section' title='Expand / Collaspe' width=10 height=10>
                                                $display_header <br/></a>
                                                <div id=$div_instance name=$div_instance
                                                style="overflow:hidden;display:$display_option;margin-left:30px; margin-top:20px;">
                                                <-- your content -->
                                                </div>
                                                <script language="JavaScript" type="text/javascript">
                                                <!--
                                                function collapsible(theID,imageID) {
                                                var elemnt = document.getElementById(theID);
                                                var imageObject =document.getElementById(imageID);
                                                if(elemnt.style.display == 'block') {
                                                elemnt.style.display ='none';
                                                imageObject.src='images/expand_icon.gif';
                                                }
                                                else{
                                                elemnt.style.display ='block';
                                                imageObject.src='images/expand_icon_down.gif';
                                                }

                                                }
                                                // -->
                                                </script>


                                                REF: http://www.ssiddique.info/simple-javascript-to-create-dynamic-collapsible-section.html







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Oct 23 '12 at 18:12









                                                Shahid SiddiqueShahid Siddique

                                                172110




                                                172110























                                                    1














                                                    As of jquery mobile beta2 you trigger an event - .trigger('create')






                                                    share|improve this answer




























                                                      1














                                                      As of jquery mobile beta2 you trigger an event - .trigger('create')






                                                      share|improve this answer


























                                                        1












                                                        1








                                                        1







                                                        As of jquery mobile beta2 you trigger an event - .trigger('create')






                                                        share|improve this answer













                                                        As of jquery mobile beta2 you trigger an event - .trigger('create')







                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered Nov 22 '12 at 12:35









                                                        AmitAmit

                                                        161415




                                                        161415























                                                            1














                                                            you can refresh the collapsible using the following code



                                                            $('#element').collapsibleset('refresh');


                                                            Hope it helps






                                                            share|improve this answer




























                                                              1














                                                              you can refresh the collapsible using the following code



                                                              $('#element').collapsibleset('refresh');


                                                              Hope it helps






                                                              share|improve this answer


























                                                                1












                                                                1








                                                                1







                                                                you can refresh the collapsible using the following code



                                                                $('#element').collapsibleset('refresh');


                                                                Hope it helps






                                                                share|improve this answer













                                                                you can refresh the collapsible using the following code



                                                                $('#element').collapsibleset('refresh');


                                                                Hope it helps







                                                                share|improve this answer












                                                                share|improve this answer



                                                                share|improve this answer










                                                                answered Jan 30 '13 at 23:45









                                                                Sagar GalaSagar Gala

                                                                824109




                                                                824109























                                                                    0














                                                                    You have to append them to the right place (e.g. under a data-role="page" element) then call .page() to initialize the content you appended, like this:



                                                                    $('<div data-role="collapsible"><h3>Title</h3><p>Content</p></div>')
                                                                    .appendTo('#someElement').page();


                                                                    You can test it out here.






                                                                    share|improve this answer
























                                                                    • very nice code - thank you.... followup question, how would you turn the two items into a single seamless item?

                                                                      – pithhelmet
                                                                      Oct 10 '12 at 20:17











                                                                    • @pithhelmet - not sure I understand what you're asking to do, can you clarify a bit?

                                                                      – Nick Craver
                                                                      Oct 10 '12 at 21:34











                                                                    • sure - your example shows two distinct items, i'm a header and title... they are separated by a space... is there a way to smash those two items into a seamless box... like this jquerymobile.com/demos/1.0rc3/docs/content/…

                                                                      – pithhelmet
                                                                      Oct 10 '12 at 21:50











                                                                    • @pithhelmet - just needed a newer version of jquery UI than the fiddle above was using, is this what you're after? jsfiddle.net/TYscV/566 (ignore the missing icons...seems to be an issue with jsfiddle including the CDN CSS)

                                                                      – Nick Craver
                                                                      Oct 10 '12 at 22:13
















                                                                    0














                                                                    You have to append them to the right place (e.g. under a data-role="page" element) then call .page() to initialize the content you appended, like this:



                                                                    $('<div data-role="collapsible"><h3>Title</h3><p>Content</p></div>')
                                                                    .appendTo('#someElement').page();


                                                                    You can test it out here.






                                                                    share|improve this answer
























                                                                    • very nice code - thank you.... followup question, how would you turn the two items into a single seamless item?

                                                                      – pithhelmet
                                                                      Oct 10 '12 at 20:17











                                                                    • @pithhelmet - not sure I understand what you're asking to do, can you clarify a bit?

                                                                      – Nick Craver
                                                                      Oct 10 '12 at 21:34











                                                                    • sure - your example shows two distinct items, i'm a header and title... they are separated by a space... is there a way to smash those two items into a seamless box... like this jquerymobile.com/demos/1.0rc3/docs/content/…

                                                                      – pithhelmet
                                                                      Oct 10 '12 at 21:50











                                                                    • @pithhelmet - just needed a newer version of jquery UI than the fiddle above was using, is this what you're after? jsfiddle.net/TYscV/566 (ignore the missing icons...seems to be an issue with jsfiddle including the CDN CSS)

                                                                      – Nick Craver
                                                                      Oct 10 '12 at 22:13














                                                                    0












                                                                    0








                                                                    0







                                                                    You have to append them to the right place (e.g. under a data-role="page" element) then call .page() to initialize the content you appended, like this:



                                                                    $('<div data-role="collapsible"><h3>Title</h3><p>Content</p></div>')
                                                                    .appendTo('#someElement').page();


                                                                    You can test it out here.






                                                                    share|improve this answer













                                                                    You have to append them to the right place (e.g. under a data-role="page" element) then call .page() to initialize the content you appended, like this:



                                                                    $('<div data-role="collapsible"><h3>Title</h3><p>Content</p></div>')
                                                                    .appendTo('#someElement').page();


                                                                    You can test it out here.







                                                                    share|improve this answer












                                                                    share|improve this answer



                                                                    share|improve this answer










                                                                    answered Nov 18 '10 at 12:39









                                                                    Nick CraverNick Craver

                                                                    532k11511951102




                                                                    532k11511951102













                                                                    • very nice code - thank you.... followup question, how would you turn the two items into a single seamless item?

                                                                      – pithhelmet
                                                                      Oct 10 '12 at 20:17











                                                                    • @pithhelmet - not sure I understand what you're asking to do, can you clarify a bit?

                                                                      – Nick Craver
                                                                      Oct 10 '12 at 21:34











                                                                    • sure - your example shows two distinct items, i'm a header and title... they are separated by a space... is there a way to smash those two items into a seamless box... like this jquerymobile.com/demos/1.0rc3/docs/content/…

                                                                      – pithhelmet
                                                                      Oct 10 '12 at 21:50











                                                                    • @pithhelmet - just needed a newer version of jquery UI than the fiddle above was using, is this what you're after? jsfiddle.net/TYscV/566 (ignore the missing icons...seems to be an issue with jsfiddle including the CDN CSS)

                                                                      – Nick Craver
                                                                      Oct 10 '12 at 22:13



















                                                                    • very nice code - thank you.... followup question, how would you turn the two items into a single seamless item?

                                                                      – pithhelmet
                                                                      Oct 10 '12 at 20:17











                                                                    • @pithhelmet - not sure I understand what you're asking to do, can you clarify a bit?

                                                                      – Nick Craver
                                                                      Oct 10 '12 at 21:34











                                                                    • sure - your example shows two distinct items, i'm a header and title... they are separated by a space... is there a way to smash those two items into a seamless box... like this jquerymobile.com/demos/1.0rc3/docs/content/…

                                                                      – pithhelmet
                                                                      Oct 10 '12 at 21:50











                                                                    • @pithhelmet - just needed a newer version of jquery UI than the fiddle above was using, is this what you're after? jsfiddle.net/TYscV/566 (ignore the missing icons...seems to be an issue with jsfiddle including the CDN CSS)

                                                                      – Nick Craver
                                                                      Oct 10 '12 at 22:13

















                                                                    very nice code - thank you.... followup question, how would you turn the two items into a single seamless item?

                                                                    – pithhelmet
                                                                    Oct 10 '12 at 20:17





                                                                    very nice code - thank you.... followup question, how would you turn the two items into a single seamless item?

                                                                    – pithhelmet
                                                                    Oct 10 '12 at 20:17













                                                                    @pithhelmet - not sure I understand what you're asking to do, can you clarify a bit?

                                                                    – Nick Craver
                                                                    Oct 10 '12 at 21:34





                                                                    @pithhelmet - not sure I understand what you're asking to do, can you clarify a bit?

                                                                    – Nick Craver
                                                                    Oct 10 '12 at 21:34













                                                                    sure - your example shows two distinct items, i'm a header and title... they are separated by a space... is there a way to smash those two items into a seamless box... like this jquerymobile.com/demos/1.0rc3/docs/content/…

                                                                    – pithhelmet
                                                                    Oct 10 '12 at 21:50





                                                                    sure - your example shows two distinct items, i'm a header and title... they are separated by a space... is there a way to smash those two items into a seamless box... like this jquerymobile.com/demos/1.0rc3/docs/content/…

                                                                    – pithhelmet
                                                                    Oct 10 '12 at 21:50













                                                                    @pithhelmet - just needed a newer version of jquery UI than the fiddle above was using, is this what you're after? jsfiddle.net/TYscV/566 (ignore the missing icons...seems to be an issue with jsfiddle including the CDN CSS)

                                                                    – Nick Craver
                                                                    Oct 10 '12 at 22:13





                                                                    @pithhelmet - just needed a newer version of jquery UI than the fiddle above was using, is this what you're after? jsfiddle.net/TYscV/566 (ignore the missing icons...seems to be an issue with jsfiddle including the CDN CSS)

                                                                    – Nick Craver
                                                                    Oct 10 '12 at 22:13











                                                                    0














                                                                    Better than collapsible is updatelayout, it is in the docs. In short...




                                                                    This event is triggered by components within the framework that dynamically show/hide content, and is meant as a generic mechanism to notify other components that they may need to update their size or position. Within the framework, this event is fired on the component element whose content was shown/hidden, and bubbles all the way up to the document element.




                                                                    $('div[data-role=collapsible]')
                                                                    .trigger( 'updatelayout' );
                                                                    //.collapsible();





                                                                    share|improve this answer




























                                                                      0














                                                                      Better than collapsible is updatelayout, it is in the docs. In short...




                                                                      This event is triggered by components within the framework that dynamically show/hide content, and is meant as a generic mechanism to notify other components that they may need to update their size or position. Within the framework, this event is fired on the component element whose content was shown/hidden, and bubbles all the way up to the document element.




                                                                      $('div[data-role=collapsible]')
                                                                      .trigger( 'updatelayout' );
                                                                      //.collapsible();





                                                                      share|improve this answer


























                                                                        0












                                                                        0








                                                                        0







                                                                        Better than collapsible is updatelayout, it is in the docs. In short...




                                                                        This event is triggered by components within the framework that dynamically show/hide content, and is meant as a generic mechanism to notify other components that they may need to update their size or position. Within the framework, this event is fired on the component element whose content was shown/hidden, and bubbles all the way up to the document element.




                                                                        $('div[data-role=collapsible]')
                                                                        .trigger( 'updatelayout' );
                                                                        //.collapsible();





                                                                        share|improve this answer













                                                                        Better than collapsible is updatelayout, it is in the docs. In short...




                                                                        This event is triggered by components within the framework that dynamically show/hide content, and is meant as a generic mechanism to notify other components that they may need to update their size or position. Within the framework, this event is fired on the component element whose content was shown/hidden, and bubbles all the way up to the document element.




                                                                        $('div[data-role=collapsible]')
                                                                        .trigger( 'updatelayout' );
                                                                        //.collapsible();






                                                                        share|improve this answer












                                                                        share|improve this answer



                                                                        share|improve this answer










                                                                        answered Dec 19 '11 at 21:08









                                                                        TMBTMB

                                                                        3,45441943




                                                                        3,45441943























                                                                            0














                                                                            This way you can add small collapsibles in a bigger one dynamically.
                                                                            HTML:



                                                                            <div data-role="collapsible" data-mini="false" data-theme="b"  >
                                                                            <h3>main header text</h3>
                                                                            <div id="aCollaps"></div>
                                                                            </div>


                                                                            Javascript



                                                                            //Your could do for(){
                                                                            $("#aCollaps").append('<div data-role="collapsible" data-inset="false" data-content-theme="b">' +
                                                                            '<h3>'+HeaderText+'</h3>'+ContentText+'<br/></div>');
                                                                            //}
                                                                            //You might want to be more specific here if you have more collapsibles in the page. this just updates all collapsibles
                                                                            $('div[data-role=collapsible]').collapsible({refresh:true});





                                                                            share|improve this answer




























                                                                              0














                                                                              This way you can add small collapsibles in a bigger one dynamically.
                                                                              HTML:



                                                                              <div data-role="collapsible" data-mini="false" data-theme="b"  >
                                                                              <h3>main header text</h3>
                                                                              <div id="aCollaps"></div>
                                                                              </div>


                                                                              Javascript



                                                                              //Your could do for(){
                                                                              $("#aCollaps").append('<div data-role="collapsible" data-inset="false" data-content-theme="b">' +
                                                                              '<h3>'+HeaderText+'</h3>'+ContentText+'<br/></div>');
                                                                              //}
                                                                              //You might want to be more specific here if you have more collapsibles in the page. this just updates all collapsibles
                                                                              $('div[data-role=collapsible]').collapsible({refresh:true});





                                                                              share|improve this answer


























                                                                                0












                                                                                0








                                                                                0







                                                                                This way you can add small collapsibles in a bigger one dynamically.
                                                                                HTML:



                                                                                <div data-role="collapsible" data-mini="false" data-theme="b"  >
                                                                                <h3>main header text</h3>
                                                                                <div id="aCollaps"></div>
                                                                                </div>


                                                                                Javascript



                                                                                //Your could do for(){
                                                                                $("#aCollaps").append('<div data-role="collapsible" data-inset="false" data-content-theme="b">' +
                                                                                '<h3>'+HeaderText+'</h3>'+ContentText+'<br/></div>');
                                                                                //}
                                                                                //You might want to be more specific here if you have more collapsibles in the page. this just updates all collapsibles
                                                                                $('div[data-role=collapsible]').collapsible({refresh:true});





                                                                                share|improve this answer













                                                                                This way you can add small collapsibles in a bigger one dynamically.
                                                                                HTML:



                                                                                <div data-role="collapsible" data-mini="false" data-theme="b"  >
                                                                                <h3>main header text</h3>
                                                                                <div id="aCollaps"></div>
                                                                                </div>


                                                                                Javascript



                                                                                //Your could do for(){
                                                                                $("#aCollaps").append('<div data-role="collapsible" data-inset="false" data-content-theme="b">' +
                                                                                '<h3>'+HeaderText+'</h3>'+ContentText+'<br/></div>');
                                                                                //}
                                                                                //You might want to be more specific here if you have more collapsibles in the page. this just updates all collapsibles
                                                                                $('div[data-role=collapsible]').collapsible({refresh:true});






                                                                                share|improve this answer












                                                                                share|improve this answer



                                                                                share|improve this answer










                                                                                answered Feb 20 '13 at 13:56









                                                                                HerskerHersker

                                                                                517511




                                                                                517511























                                                                                    0














                                                                                    Here's an example of what I did to dynamically change my collapsible. I had a few arrays that I needed to display as headers, and then I needed a grid in each collapsible set with 2 sides, one for question and one for answer.



                                                                                       var inputList = '';
                                                                                    var count = 0;
                                                                                    var divnum = 999;
                                                                                    var collit = 'false';
                                                                                    inputList += '<div data-role="content">';
                                                                                    inputList += '<div id="fb_showings_collapse" data-role="collapsible-set" data-theme="b">';
                                                                                    $.each(fbFullStrArray, function(index, item) {
                                                                                    //set questions and answers for each appt
                                                                                    getsetApptFback(fbStrApptArray[index]);
                                                                                    //write the html to append when done
                                                                                    inputList += '<div data-role="collapsible" data-collapsed="'+collit+'">';
                                                                                    inputList += '<h3>'+fbFullStrArray[index]+'</h3>';
                                                                                    inputList += '<div id="g'+divnum+'" class="ui-grid-a">';
                                                                                    inputList += '<div id="gb'+divnum+'" class="ui-block-a">';
                                                                                    inputList += '<div id="fbq'+index+'"><ol>';
                                                                                    $.each(fbQidArray, function(ind,it) {
                                                                                    inputList += '<li>'+fbQuestionArray[ind]+'<b></b></li>';
                                                                                    });
                                                                                    inputList += '</ol></div></div>'
                                                                                    inputList += '<div id="ga'+divnum+'" class="ui-block-b">';
                                                                                    inputList += '<div id="fba'+index+'"><ul>';
                                                                                    $.each(fbQidArray, function(ind,it){
                                                                                    inputList += '<li>'+fbAnswerArray[ind]+'<b></b></li>';
                                                                                    });
                                                                                    inputList += '</ul></div></div></div></div>';
                                                                                    collit = "true";
                                                                                    divnum++;
                                                                                    count++;
                                                                                    });
                                                                                    inputList += '</div></div>';

                                                                                    $('#fb_showings_collapse [role=collapsible-set]').text('');
                                                                                    $('#fb_showings_collapse [role=collapsible]').text('');
                                                                                    if (count > 0) {
                                                                                    $('#fb_showings_collapse [role=collapsible]').remove();
                                                                                    $('#fb_showings_collapse').append(inputList).collapsibleset('refresh');
                                                                                    }
                                                                                    else if (count == 0){
                                                                                    inputList = 'Sorry! No Showings To Show Feedback For!';
                                                                                    $('#fb_showings_collapse [role=collapsible-set').remove();
                                                                                    $('#fb_showings_collapse [role=collapsible]').text(inputList);
                                                                                    }





                                                                                    share|improve this answer




























                                                                                      0














                                                                                      Here's an example of what I did to dynamically change my collapsible. I had a few arrays that I needed to display as headers, and then I needed a grid in each collapsible set with 2 sides, one for question and one for answer.



                                                                                         var inputList = '';
                                                                                      var count = 0;
                                                                                      var divnum = 999;
                                                                                      var collit = 'false';
                                                                                      inputList += '<div data-role="content">';
                                                                                      inputList += '<div id="fb_showings_collapse" data-role="collapsible-set" data-theme="b">';
                                                                                      $.each(fbFullStrArray, function(index, item) {
                                                                                      //set questions and answers for each appt
                                                                                      getsetApptFback(fbStrApptArray[index]);
                                                                                      //write the html to append when done
                                                                                      inputList += '<div data-role="collapsible" data-collapsed="'+collit+'">';
                                                                                      inputList += '<h3>'+fbFullStrArray[index]+'</h3>';
                                                                                      inputList += '<div id="g'+divnum+'" class="ui-grid-a">';
                                                                                      inputList += '<div id="gb'+divnum+'" class="ui-block-a">';
                                                                                      inputList += '<div id="fbq'+index+'"><ol>';
                                                                                      $.each(fbQidArray, function(ind,it) {
                                                                                      inputList += '<li>'+fbQuestionArray[ind]+'<b></b></li>';
                                                                                      });
                                                                                      inputList += '</ol></div></div>'
                                                                                      inputList += '<div id="ga'+divnum+'" class="ui-block-b">';
                                                                                      inputList += '<div id="fba'+index+'"><ul>';
                                                                                      $.each(fbQidArray, function(ind,it){
                                                                                      inputList += '<li>'+fbAnswerArray[ind]+'<b></b></li>';
                                                                                      });
                                                                                      inputList += '</ul></div></div></div></div>';
                                                                                      collit = "true";
                                                                                      divnum++;
                                                                                      count++;
                                                                                      });
                                                                                      inputList += '</div></div>';

                                                                                      $('#fb_showings_collapse [role=collapsible-set]').text('');
                                                                                      $('#fb_showings_collapse [role=collapsible]').text('');
                                                                                      if (count > 0) {
                                                                                      $('#fb_showings_collapse [role=collapsible]').remove();
                                                                                      $('#fb_showings_collapse').append(inputList).collapsibleset('refresh');
                                                                                      }
                                                                                      else if (count == 0){
                                                                                      inputList = 'Sorry! No Showings To Show Feedback For!';
                                                                                      $('#fb_showings_collapse [role=collapsible-set').remove();
                                                                                      $('#fb_showings_collapse [role=collapsible]').text(inputList);
                                                                                      }





                                                                                      share|improve this answer


























                                                                                        0












                                                                                        0








                                                                                        0







                                                                                        Here's an example of what I did to dynamically change my collapsible. I had a few arrays that I needed to display as headers, and then I needed a grid in each collapsible set with 2 sides, one for question and one for answer.



                                                                                           var inputList = '';
                                                                                        var count = 0;
                                                                                        var divnum = 999;
                                                                                        var collit = 'false';
                                                                                        inputList += '<div data-role="content">';
                                                                                        inputList += '<div id="fb_showings_collapse" data-role="collapsible-set" data-theme="b">';
                                                                                        $.each(fbFullStrArray, function(index, item) {
                                                                                        //set questions and answers for each appt
                                                                                        getsetApptFback(fbStrApptArray[index]);
                                                                                        //write the html to append when done
                                                                                        inputList += '<div data-role="collapsible" data-collapsed="'+collit+'">';
                                                                                        inputList += '<h3>'+fbFullStrArray[index]+'</h3>';
                                                                                        inputList += '<div id="g'+divnum+'" class="ui-grid-a">';
                                                                                        inputList += '<div id="gb'+divnum+'" class="ui-block-a">';
                                                                                        inputList += '<div id="fbq'+index+'"><ol>';
                                                                                        $.each(fbQidArray, function(ind,it) {
                                                                                        inputList += '<li>'+fbQuestionArray[ind]+'<b></b></li>';
                                                                                        });
                                                                                        inputList += '</ol></div></div>'
                                                                                        inputList += '<div id="ga'+divnum+'" class="ui-block-b">';
                                                                                        inputList += '<div id="fba'+index+'"><ul>';
                                                                                        $.each(fbQidArray, function(ind,it){
                                                                                        inputList += '<li>'+fbAnswerArray[ind]+'<b></b></li>';
                                                                                        });
                                                                                        inputList += '</ul></div></div></div></div>';
                                                                                        collit = "true";
                                                                                        divnum++;
                                                                                        count++;
                                                                                        });
                                                                                        inputList += '</div></div>';

                                                                                        $('#fb_showings_collapse [role=collapsible-set]').text('');
                                                                                        $('#fb_showings_collapse [role=collapsible]').text('');
                                                                                        if (count > 0) {
                                                                                        $('#fb_showings_collapse [role=collapsible]').remove();
                                                                                        $('#fb_showings_collapse').append(inputList).collapsibleset('refresh');
                                                                                        }
                                                                                        else if (count == 0){
                                                                                        inputList = 'Sorry! No Showings To Show Feedback For!';
                                                                                        $('#fb_showings_collapse [role=collapsible-set').remove();
                                                                                        $('#fb_showings_collapse [role=collapsible]').text(inputList);
                                                                                        }





                                                                                        share|improve this answer













                                                                                        Here's an example of what I did to dynamically change my collapsible. I had a few arrays that I needed to display as headers, and then I needed a grid in each collapsible set with 2 sides, one for question and one for answer.



                                                                                           var inputList = '';
                                                                                        var count = 0;
                                                                                        var divnum = 999;
                                                                                        var collit = 'false';
                                                                                        inputList += '<div data-role="content">';
                                                                                        inputList += '<div id="fb_showings_collapse" data-role="collapsible-set" data-theme="b">';
                                                                                        $.each(fbFullStrArray, function(index, item) {
                                                                                        //set questions and answers for each appt
                                                                                        getsetApptFback(fbStrApptArray[index]);
                                                                                        //write the html to append when done
                                                                                        inputList += '<div data-role="collapsible" data-collapsed="'+collit+'">';
                                                                                        inputList += '<h3>'+fbFullStrArray[index]+'</h3>';
                                                                                        inputList += '<div id="g'+divnum+'" class="ui-grid-a">';
                                                                                        inputList += '<div id="gb'+divnum+'" class="ui-block-a">';
                                                                                        inputList += '<div id="fbq'+index+'"><ol>';
                                                                                        $.each(fbQidArray, function(ind,it) {
                                                                                        inputList += '<li>'+fbQuestionArray[ind]+'<b></b></li>';
                                                                                        });
                                                                                        inputList += '</ol></div></div>'
                                                                                        inputList += '<div id="ga'+divnum+'" class="ui-block-b">';
                                                                                        inputList += '<div id="fba'+index+'"><ul>';
                                                                                        $.each(fbQidArray, function(ind,it){
                                                                                        inputList += '<li>'+fbAnswerArray[ind]+'<b></b></li>';
                                                                                        });
                                                                                        inputList += '</ul></div></div></div></div>';
                                                                                        collit = "true";
                                                                                        divnum++;
                                                                                        count++;
                                                                                        });
                                                                                        inputList += '</div></div>';

                                                                                        $('#fb_showings_collapse [role=collapsible-set]').text('');
                                                                                        $('#fb_showings_collapse [role=collapsible]').text('');
                                                                                        if (count > 0) {
                                                                                        $('#fb_showings_collapse [role=collapsible]').remove();
                                                                                        $('#fb_showings_collapse').append(inputList).collapsibleset('refresh');
                                                                                        }
                                                                                        else if (count == 0){
                                                                                        inputList = 'Sorry! No Showings To Show Feedback For!';
                                                                                        $('#fb_showings_collapse [role=collapsible-set').remove();
                                                                                        $('#fb_showings_collapse [role=collapsible]').text(inputList);
                                                                                        }






                                                                                        share|improve this answer












                                                                                        share|improve this answer



                                                                                        share|improve this answer










                                                                                        answered Jun 8 '13 at 9:14









                                                                                        mIKE - mDKmIKE - mDK

                                                                                        1




                                                                                        1























                                                                                            0














                                                                                            See the enhanceWithin() function: jQuery Mobile docs: enhanceWithin



                                                                                            Call enhanceWithin on a jQuery object representing your DOM element's parent to have any jQuery Mobile features added to your HTML.



                                                                                            In this case:



                                                                                            jQuery('[data-role="collapsible"]').parent().enhanceWithin();


                                                                                            Note that if you are adding multiple jQuery Mobile widgets you may only want to call enhanceWithin on an ancestor such as "BODY" after adding all your dynamic HTML.



                                                                                            This would be a pretty good solution for this question as well: Refresh a section after adding HTML dynamically to jquery mobile






                                                                                            share|improve this answer






























                                                                                              0














                                                                                              See the enhanceWithin() function: jQuery Mobile docs: enhanceWithin



                                                                                              Call enhanceWithin on a jQuery object representing your DOM element's parent to have any jQuery Mobile features added to your HTML.



                                                                                              In this case:



                                                                                              jQuery('[data-role="collapsible"]').parent().enhanceWithin();


                                                                                              Note that if you are adding multiple jQuery Mobile widgets you may only want to call enhanceWithin on an ancestor such as "BODY" after adding all your dynamic HTML.



                                                                                              This would be a pretty good solution for this question as well: Refresh a section after adding HTML dynamically to jquery mobile






                                                                                              share|improve this answer




























                                                                                                0












                                                                                                0








                                                                                                0







                                                                                                See the enhanceWithin() function: jQuery Mobile docs: enhanceWithin



                                                                                                Call enhanceWithin on a jQuery object representing your DOM element's parent to have any jQuery Mobile features added to your HTML.



                                                                                                In this case:



                                                                                                jQuery('[data-role="collapsible"]').parent().enhanceWithin();


                                                                                                Note that if you are adding multiple jQuery Mobile widgets you may only want to call enhanceWithin on an ancestor such as "BODY" after adding all your dynamic HTML.



                                                                                                This would be a pretty good solution for this question as well: Refresh a section after adding HTML dynamically to jquery mobile






                                                                                                share|improve this answer















                                                                                                See the enhanceWithin() function: jQuery Mobile docs: enhanceWithin



                                                                                                Call enhanceWithin on a jQuery object representing your DOM element's parent to have any jQuery Mobile features added to your HTML.



                                                                                                In this case:



                                                                                                jQuery('[data-role="collapsible"]').parent().enhanceWithin();


                                                                                                Note that if you are adding multiple jQuery Mobile widgets you may only want to call enhanceWithin on an ancestor such as "BODY" after adding all your dynamic HTML.



                                                                                                This would be a pretty good solution for this question as well: Refresh a section after adding HTML dynamically to jquery mobile







                                                                                                share|improve this answer














                                                                                                share|improve this answer



                                                                                                share|improve this answer








                                                                                                edited May 23 '17 at 11:45









                                                                                                Community

                                                                                                11




                                                                                                11










                                                                                                answered May 23 '14 at 18:45









                                                                                                MatthewMatthew

                                                                                                4,74863055




                                                                                                4,74863055






























                                                                                                    draft saved

                                                                                                    draft discarded




















































                                                                                                    Thanks for contributing an answer to Stack Overflow!


                                                                                                    • Please be sure to answer the question. Provide details and share your research!

                                                                                                    But avoid



                                                                                                    • Asking for help, clarification, or responding to other answers.

                                                                                                    • Making statements based on opinion; back them up with references or personal experience.


                                                                                                    To learn more, see our tips on writing great answers.




                                                                                                    draft saved


                                                                                                    draft discarded














                                                                                                    StackExchange.ready(
                                                                                                    function () {
                                                                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4214538%2fdynamically-adding-collapsible-elements%23new-answer', 'question_page');
                                                                                                    }
                                                                                                    );

                                                                                                    Post as a guest















                                                                                                    Required, but never shown





















































                                                                                                    Required, but never shown














                                                                                                    Required, but never shown












                                                                                                    Required, but never shown







                                                                                                    Required, but never shown

































                                                                                                    Required, but never shown














                                                                                                    Required, but never shown












                                                                                                    Required, but never shown







                                                                                                    Required, but never shown







                                                                                                    Popular posts from this blog

                                                                                                    Bressuire

                                                                                                    Vorschmack

                                                                                                    Quarantine