Register  |  Login



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
Answer Summaries

 

Q&A System for Websites and Corporate Collaboration

Advertisement

  • Generates significant organic traffic for websites
  • Saves companies money, resources, and time

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.

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 an Answer Summary for the Summary 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 summaries 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 Web Design Experts

View More

Rank

Expert

Points

1.

rcastagna

635

2.

nidhi

540

3.

xarcus

505

4.

jgivoni

330

5.

m.j.little

250

6.

redcharcoal

200

7.

Snyke

175

8.

PeterNZ

165

9.

danmacryan

125

10.

lclbus

125

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