Adding div tag below another div tag

position div below another div with position: absolute
how to make a div go below another
scroll div under another div
center a div below another div
div below each other
align div with another div
overlapping div on top of another
div appear below another

I have a div tag with class divstudent, lets say this is div1 tag. Now I want to create another div tag div2 dynamically below this div1 tag, not inside of the div1 tag. I want to create outside of div1 tag using javascript. How can I do that?

"div1"
<div class="divstudent"></div>

<!-- i want to be like this -->
<!-- "div1" -->
<div></div>

<!-- "div2" -->
<div></div>

<!-- "div3" -->
<div></div>

Try something like this:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Divs creator</title>

    <script type="text/javascript">
        window.onload = function () {
            var divReference = document.querySelector('.divstudent');
            var divCounter = 0;
            divReference.addEventListener('click', function () {
                var divToCreate = document.createElement('div');
                divToCreate.innerHTML = ++divCounter;
                divReference.parentNode.appendChild(divToCreate);
            }, false);
        }
    </script>
</head>
<body>
    <div class="divstudent">
        <input type="button" value="add div below divstudent">
    </div>

</body>
</html>

How to place a div below another div?, hello guys, am using a .net master page and trying to align a div with a nested navigation link above another div. Such that I can add a  // Grab the div you want to insert your new div after var target_div = document.querySelector("div.divstudent"); // Insert newDiv after target_div (before the thing after it) target_div.parentNode.insertBefore(newDiv, target_div.nextSibling);

There are many ways to do this. One significant difference in methods is if you choose to create the elements first using Document.createElement() and then insert the elements, or create and insert the elements in one step using one of the methods that allows you to insert HTML text.

Because it is simpler, but not necessarily better, the examples below show creating and inserting the two <div> elements in a single step using methods that allow inserting HTML text into the DOM.

JavaScript: One is to use insertAdjacentHTML() and specify that it is to be inserted afterend of the element you are using.

document.querySelector() is used to find the first <div class="divstudent">. Then insertAdjacentHTML() is used to add the additional <div> elements. Element.removeAttribute() is then used to remove the class="divstudent". Note: if we had just wanted to set teh class to something different, even '', then we could have used Element.className.

NOTE: In this answer, text identifying each <div> has been added to the <div>s so there is something visible in the examples in this answer.

//Find the first <div class="divstudent"> in the document
var studentDiv = document.querySelector('div.divstudent');
//Insert two new <div> elements.
studentDiv.insertAdjacentHTML('afterend','<div>2</div><div>3</div>');
//Remove the class="divstudent"
studentDiv.removeAttribute('class');
<div class="divstudent">1</div>

Align a div below another - HTML & CSS, So I have a fixed div with title and image below the title, and I want to then have another div, in the flow immediately under the fixed div. learning a plugin like ScrollMagic.js, especially if you're going to add an animation. Adding a Div Element To Place an Item Add an absolute positioned div element with CSS tutorial In this short tutorial we will add an element (image, text) to an HTML page, then locate it on the page using css code to move it to any location.

$(function() {
  $("div").eq(0).after("<div>This is div 2</div>");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div>
  This is div 1
</div>

Position a div below a fixed div, The second div should be direct below the fixed one. Example Luckily I found it can be solved pretty by adding another div as a wrapper. Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java and XML.

Since this is tagged jquery, just use .after()

$(function() {
  $("div").eq(0).after("<div>This is div 2</div>");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div>
  This is div 1
</div>

How to position a div after a fixed div, Weaving One Element Over and Under Another Element This adds transparency to an element by stripping white from the image to reveal Over and under border design using CSS (with img tag and without z-index). In the above output, you can see the Div place up and down because CSS Div is a block element that forces a line break before and after the element. In some situation you have to place these Div side by side. CSS Div side by side. CSS float property enables you to take an element out of normal flow and put content side-by-side.

You create a new div (in js), then just append your newDiv, after the target div. Something along the lines of in vanilla js:

// Create your new div
var newDiv = document.createElement("div");   
newDiv.innerText = "New Div!"; 
// Grab the div you want to insert your new div after   
var target_div = document.querySelector("div.divstudent");
// Insert newDiv after target_div (before the thing after it)
target_div.parentNode.insertBefore(newDiv, target_div.nextSibling);

Weaving One Element Over and Under Another Element, Hi there, is it possible to add a div containing some text below an existing div on a current page. e.g. This is the exsiting div: some. Answer: Use the CSS z-index Property 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).

adding a div below another div with a class, How to place a Div inside another Div. CSS Div (division) is a container element and it is used to group related items together. The use of div tag is straightforward​. Hi there, is it possible to add a div containing some text below an existing div on a current page. e.g. This is the exsiting div: some

Div inside another Div , how to position div center of another div, Element #5 is static, and so is drawn below the other four elements, even though it comes later in the HTML markup. DIV #1 position: absolute;. Then they added padding-top to the second div with 80px as well. Worked for pretty fixed layouts. In my case, it didn’t help, because I wanted my slideshow to look everywhere the same. I can’t tell what the height of my fixed div is. Luckily I found it can be solved pretty by adding another div as a wrapper. Imagine the following HTML code:

Stacking without the z-index property, The tag is used to define parts of a page or a document. Learn How to Horizontally Center a in Another with W3docs tutorial.

Comments
  • Just a side note, HTML comments are denoted <!-- Like this -->
  • Pretty much the same question: stackoverflow.com/questions/4793604/…
  • What have you tried? BTW: It is quite a bit easier to reference a specific element if you give it a unique id, in addition to a class.
  • Are you really wanting to remove the class="divstudent"?
  • yes i want to remove the class,and i need to create new div
  • Whoops, your right, was coding straight in to the box :p have fixed it
  • its not working for me,i am using javacript,i think i shd write function for insertAfter
  • Have updated it with fix. As Makyen pointed out I'd imagined the insertAfter method since i was writing straight in to the answer box.