Multiply a css class div element in Jquery or Javascript without the HTML -


my problem simple,

i have div class element looking this:

<div class="square">  <div class ="inner"> <img src="square.jpg" alt="square">  </div> 

now, want duplicate/multiply ".square" element until fills space of parent div "#wrapper". don't want copy paste element 200 times in html, wondering if there javascript / jquery option this.

another question if can somehow make multiplication stop when element filled whole parent div space.

i more of newbie in programming area, eager learn , discover, if question seems silly or has obvious answer please share might remember being silly 1 day.

one way of doing basic math. determine total available area , keep adding elements long total used area lesser total available area.

var outer = $('.square'), inner = $('.inner')     totalarea = outer.width() * outer.height(),      usedarea = inner.outerwidth() * inner.outerheight();  while(usedarea < totalarea) {     $('<div/>').addclass('inner').appendto(outer);     usedarea += inner.outerwidth() * inner.outerheight(); } 

working demo


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -