Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding parent div over multiple divs

I want to add a parent div.

<div id="faceone"><img src=""></div>

<div id="facetwo" ><img src=""></div>

<div id="facethree"><img src=""></div

<div id="facefour"><img src=""></div>

These are four divs and i want to add a parent div above them. I tried this

$('#faceone').wrapAll('<div class="cubeSpinner">'); 

But this is adding cubeSpinner above faceone only

<div class="cubeSpinner">

<div id="faceone"><img src=""></div>

</div>
<div id="facetwo" ><img src=""></div>

<div id="facethree"><img src=""></div

<div id="facefour"><img src=""></div>

But i want the result should be like this

<div class="cubeSpinner">

<div id="faceone"><img src=""></div>

<div id="facetwo" ><img src=""></div>

<div id="facethree"><img src=""></div

<div id="facefour"><img src=""></div>

</div>
like image 532
Owais Ahmed Avatar asked Nov 26 '15 00:11

Owais Ahmed


People also ask

How do I overlay multiple divs?

You can use the CSS position property in combination with the z-index property to overlay an individual div over another div element. The z-index property determines the stacking order for positioned elements (i.e. elements whose position value is one of absolute , fixed , or relative ).

How do I make DIVS always fit in my parent div?

Method 1: First method is to simply assign 100% width and 100% height to the child div so that it will take all available space of the parent div. Consider this HTML for demonstration: HTML.

How put div at bottom of parent?

Make the outer div position="relative" and the inner div position="absolute" and set it's bottom="0" .

What does $( div parent?

The :parent Selector page on jQuery says: Select all elements that have at least one child node (either an element or text). So $('div') would select all divs and $('div:parent') would select only those with children.


1 Answers

You need to select all the elements in order for them to be wrapped. I'd suggest adding a common class to them, but in the meantime you could use the attribute selector [id^="face"] to select all elements with an id attribute that begins with 'face':

$('[id^="face"]').wrapAll('<div class="cubeSpinner"></div>'); 
like image 74
Josh Crozier Avatar answered Sep 18 '22 19:09

Josh Crozier