Dynamically adding collapsible elements
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
add a comment |
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
add a comment |
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
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
jquery mobile
asked Nov 18 '10 at 12:05
BillBill
61113
61113
add a comment |
add a comment |
11 Answers
11
active
oldest
votes
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
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
add a comment |
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>
add a comment |
I think
after setting the innerhtml, simply tiggerring a event on it should render the dynamic contnet like below
$('#<divId or elementId').trigger("create");
add a comment |
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
add a comment |
As of jquery mobile beta2 you trigger an event - .trigger('create')
add a comment |
you can refresh the collapsible using the following code
$('#element').collapsibleset('refresh');
Hope it helps
add a comment |
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.
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
add a comment |
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();
add a comment |
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});
add a comment |
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);
}
add a comment |
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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>
add a comment |
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>
add a comment |
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>
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>
answered Aug 7 '12 at 19:22
Pablo JohnsonPablo Johnson
672920
672920
add a comment |
add a comment |
I think
after setting the innerhtml, simply tiggerring a event on it should render the dynamic contnet like below
$('#<divId or elementId').trigger("create");
add a comment |
I think
after setting the innerhtml, simply tiggerring a event on it should render the dynamic contnet like below
$('#<divId or elementId').trigger("create");
add a comment |
I think
after setting the innerhtml, simply tiggerring a event on it should render the dynamic contnet like below
$('#<divId or elementId').trigger("create");
I think
after setting the innerhtml, simply tiggerring a event on it should render the dynamic contnet like below
$('#<divId or elementId').trigger("create");
answered Jun 5 '13 at 19:05
BasavBasav
1,87011217
1,87011217
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Oct 23 '12 at 18:12
Shahid SiddiqueShahid Siddique
172110
172110
add a comment |
add a comment |
As of jquery mobile beta2 you trigger an event - .trigger('create')
add a comment |
As of jquery mobile beta2 you trigger an event - .trigger('create')
add a comment |
As of jquery mobile beta2 you trigger an event - .trigger('create')
As of jquery mobile beta2 you trigger an event - .trigger('create')
answered Nov 22 '12 at 12:35
AmitAmit
161415
161415
add a comment |
add a comment |
you can refresh the collapsible using the following code
$('#element').collapsibleset('refresh');
Hope it helps
add a comment |
you can refresh the collapsible using the following code
$('#element').collapsibleset('refresh');
Hope it helps
add a comment |
you can refresh the collapsible using the following code
$('#element').collapsibleset('refresh');
Hope it helps
you can refresh the collapsible using the following code
$('#element').collapsibleset('refresh');
Hope it helps
answered Jan 30 '13 at 23:45
Sagar GalaSagar Gala
824109
824109
add a comment |
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
answered Nov 18 '10 at 12:39
Nick Craver♦Nick 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
add a comment |
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
add a comment |
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();
add a comment |
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();
add a comment |
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();
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();
answered Dec 19 '11 at 21:08
TMBTMB
3,45441943
3,45441943
add a comment |
add a comment |
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});
add a comment |
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});
add a comment |
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});
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});
answered Feb 20 '13 at 13:56
HerskerHersker
517511
517511
add a comment |
add a comment |
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);
}
add a comment |
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);
}
add a comment |
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);
}
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);
}
answered Jun 8 '13 at 9:14
mIKE - mDKmIKE - mDK
1
1
add a comment |
add a comment |
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
add a comment |
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
add a comment |
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
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
edited May 23 '17 at 11:45
Community♦
11
11
answered May 23 '14 at 18:45
MatthewMatthew
4,74863055
4,74863055
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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