Reputation: 32321
I need to create the following HTML dynamically
<div role="main" class="ui-content oms-content">
<div class="myactivelabelsWrap">
<div data-role="collapsible" data-inset="false">
<h3>Home <a class="icon-pencil-1 labelEditIcon"></a></h3>
</div>
<div data-role="collapsible" data-inset="false">
<h3>SoftSol <a class="icon-pencil-1 labelEditIcon"></a></h3>
</div>
</div>
<div class="row">
<button class="btn btn-a">Create New Label</button>
</div>
</div>
I was trying it this way
First i defined the folowing in my HTML
<div role="main" class="ui-content oms-content">
<div class="row">
<button class="btn btn-a">Create New Label</button>
</div>
</div>
Thisis my fiddle
var response =
{
"Restaurants": [
{
"RestrntArea": "Home",
"cust_loc_id": "338"
},
{
"RestrntArea": "Soft",
"cust_loc_id": "339"
}
]
}
showLabels();
function showLabels() {
var labelsdivtemp=$('<div class="myactivelabelsWrap"></div>');
for (var i = 0; i < response.Restaurants.length; i++) {
var name = response.Restaurants[i].RestrntArea;
if(name)
{
labelsdivtemp.append('<div data-role="collapsible" data-inset="false"><h3>'+name+'<a class="icon-pencil-1 labelEditIcon"></a></h3></div>');
}
}
$("#labelsdivheader").append(labelsdivtemp);
}
My question is how to move create new label to the end ??
Upvotes: 2
Views: 164
Reputation: 2869
Here is .detach() and append used:
$buttonRow = $('#labelsdivheader .row').detach();
$("#labelsdivheader").append($buttonRow);
Upvotes: 0
Reputation: 766
You can use prepend
method instead append
:
$("#labelsdivheader").prepend(labelsdivtemp);
Here is the jsfiddle.
Upvotes: 1
Reputation: 27765
You can use insertBefore
method:
labelsdivtemp.insertBefore( '#labelsdivheader .row' );
Upvotes: 1