using Javascript to render a div tag

Posted on 2016-07-14
Last Modified: 2016-07-15
I have a html page.

Is there a way to use JavaScript to render a div that looks like this in the body section of my page. On page load.

        <div id="Div1">
Question by:maqskywalker
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 82

Assisted Solution

hielo earned 250 total points
ID: 41711247
<script type="text/javascript">
   document.getElementById("Div1").innerHTML = "<p>Hello</p>";

Open in new window

LVL 20

Accepted Solution

Russ Suter earned 250 total points
ID: 41711328
The above method would replace the entire contents of the DIV. The DOM way would be like this:
<script type="text/javascript">
    var newP = document.createElement('p');
    newP .innerHTML = "Hello";

Open in new window

This would add a div to the existing parent element without replacing existing stuff.
Or, if you are using jQuery it's even easier:

Open in new window


Author Closing Comment

ID: 41713250

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Adding a countdown to HTA 12 98
Can't get cursor to change 3 16
Text color and background in a text box. 2 25
HTML or/and CSS codes to construct numbered paragraphs. 5 21
When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question