SodaMelter SodaMelter -4 years ago 97
CSS Question

Merging divs using their div id?

Basically I have a total of about 19 divs that share 3 classes and 3 ids. Is there a way for me to join the 19 smaller divs and make them one larger one in relation to each of their relevant classes?

If code any code is required from me then feel free to ask, feeling like there could be a way to use either Concat with my MySQL statement or maybe something in the php.

Thanks

Answer Source

You can do it in javascript by grabbing their class name or their IDs. With classes it would look like this,

var smalldivs = document.getElementsByClassName("small-div");

var combined = "";
for(var i = 0; i < smalldivs.length; ++i){
combined = combined + smalldivs[i].innerHTML;
}

var newDiv = document.createElement('div');
newDiv.innerHTML = combined;

for(var i = 0; i < smalldivs.length; ++i){
  if(i == 0){
    smalldivs[i].parentNode.appendChild(newDiv);
  }
  smalldivs[i].parentNode.removeChild(smalldivs[i]);
  i = i -1;
}

Here is a jfiddle of combining divs

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download