Register  |  Login




Advertisement

Start Your Own Q&A Site

Create your own Q&A site easily, allowing you to quickly grow a new community around any subject matter or generate new organic traffic for your existing website.

Question

Status: Closed Points: 50 Time: 20:47 - Sep 11, 2006  

david

How do I create a DIV with javascript?

I want to create a DIV manually with javascript. How is that accomplished?

Answer Discussion
Tutorials

 

david

Date:: Sep 12, 2006

Time:: 09:16

I found out myself:

var newdiv = document.createElement('div');
var divIdName = 'testDiv';
newdiv.setAttribute('id',divIdName);
newdiv.style.width = "300px";
newdiv.style.height = "300px";
newdiv.style.left = "300px";
newdiv.style.top = "300px";
newdiv.style.position = "absolute";
newdiv.style.background = "#00C";
newdiv.style.border = "4px solid #000";
newdiv.innerHTML = 'Test Div';
document.body.appendChild(newdiv);

multani.sarbjit

Date:: Sep 12, 2006

Time:: 11:58

good work...now give me your points...lol

jgivoni

Date:: Sep 13, 2006

Time:: 15:17

Ok, good enough david, but what I usually do is to define the DIV in the html code like this (example with some of your attributes):

<div name="testDiv" id="divID" style="width: 300px; height: 300px; left: 300px; top: 300px; position: absolute; display: none">
Test Div
</div>

Note the "display: none" which hides it initially.

When you want to show it, just execute

document.getElementById("divID").style.display = "";

You can also create copies of it in javascript and - of course - hide it again.

I think it makes it simpler to keep layout in the html file and only let javascript handle execution.

Jakob

david

Date:: Sep 20, 2006

Time:: 11:25

Thanks, Jakob, but I needed the complete dynamic approach since it will be used on different html-pages without me being able to alter the html on beforehand.

hamiltonrohane

Date:: Dec 24, 2008

Time:: 14:30

you guy's are great!

Question Answered

This question has been closed, and points have been rewarded to the following experts:


david: 40
jgivoni: 10

You're welcome however to comment or give additional information or if you wish, you have the ability to write a Tutorial in the Tutorial Area.

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

No tutorials have been submitted yet. Want to be the first?

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top Experts

View More

Rank

Expert

Points

1.

nidhi

10279

2.

oracleofDelphi

6493

3.

rcastagna

5596

4.

LAGM

4848

5.

PeterNZ

3487

6.

gonzalo

2840

7.

Mason

2770

8.

jgivoni

2303

9.

xarcus

1820

10.

Anpanman

917

Become an Expert

Register today to share your knowledge with the community and be recognized and rewarded for your contributions.


Register Here




"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it



Language Options

English:

www.quomon.com

Español:

www.quomon.es