Skip to content Skip to sidebar Skip to footer

How To Repeat Div Using Jquery Or Javascript?

I have an HTML page with the following div tags

Solution 1:

So you want cloneNode of your div, so try something like this

var div = document.getElementById('myDiv'),
clone = div.cloneNode(true);
clone.id = "some_id";
document.body.appendChild(clone);

Solution 2:

Something like this? Sample Fiddle

var lastSection = $('[data-role="page"]:last'); //get the last page probably you can use this to increment the id based on last idvar newSection = lastSection.clone(false);//default is false anyways, if you want to carry over data and events you can use true.
newSection.attr('id','setthenewid');//set the new id
$('div[class^=dydivarr]',newSection).attr('class','newclass'); //set the new class for your divarr
$('.ui-btn-right a',newSection).attr('href','newurlmap');//set the new url map 
lastSection.after(newSection); //place the entire page section in the end

Solution 3:

Update :

Simple Code worked. It was just my wrong approach

<scripttype="text/javascript">

for(var lp=0; lp < 10; lp++)
{
document.write('<divdata-role="page"id="page'+lp+'"data-theme="a">');
document.write('  <divdata-role="content">');
document.write('    <center>');
document.write('      <h3><ahref="#page0"data-role="none"><imgsrc="images/logo.png" /></a></h3>');
document.write('     </center>');
document.write('     <divclass="dydivarr+lp+'"></div>');
document.write('     <br /> ');
document.write('     <divdata-role="controlgroup"class="ui-btn-left"><ahref="#page'+(lp-1)+'"data-role="button">Previous</a></div>');
document.write('     <divdata-role="controlgroup"class="ui-btn-right"><ahref="#page'+(lp+1)+'"data-role="button">Next</a></div>');
document.write('   </div>');
document.write(' </div>');

}

</script>

Thanks

Solution 4:

How can I replicate a div a certain number of times based on a select-box value?

Roko C. Buljan

And

Vivin Paliath

's Answers

Post a Comment for "How To Repeat Div Using Jquery Or Javascript?"