Setting top and left CSS attributes

0 votes

I can't seem to get the "top" and "left" CSS attributes to work with the following JavaScript.

var div = document.createElement('div');
div.style.position = 'absolute';
div.style.top = 300;
div.style.left = 300;
document.body.appendChild(div);

I can see that the div's position is set to "absolute" in Firebug, but the top and left attributes are not!

This is a Firefox 3.6 add-on.

Jun 9 in CSS by Edureka
• 7,940 points
8 views

1 answer to this question.

0 votes

You can alternatively use the setProperty method, which is seen below.

document.getElementById('divName').style.setProperty("top", "100px");
answered Jun 10 by Edureka
• 8,460 points

Related Questions In CSS

0 votes
1 answer

How to create material design input form using css and bootstrap?

Try with this code. HTML: <div class="main_div"> ...READ MORE

answered Jun 21 in CSS by Edureka
• 8,460 points
20 views
0 votes
1 answer
0 votes
1 answer

What is the difference between CSS and SCSS?

CSS: Cascading Style Sheets (CSS) is a ...READ MORE

answered Jun 17 in CSS by Edureka
• 8,460 points
7 views
0 votes
1 answer

What is WebKit and how is it related to CSS?

In the CSS syntax for rendering content ...READ MORE

answered Jun 17 in CSS by Edureka
• 8,460 points
5 views
0 votes
1 answer

Presenting docket dtates inside html page by javascript

Use the Docker Engine Api:Docker Engine API ...READ MORE

answered Jun 20, 2018 in Docker by DareDev
• 6,890 points
211 views
0 votes
1 answer

Migrating proxy npm repo in nexus 3

I don't think you can achieve this ...READ MORE

answered Jun 22, 2018 in DevOps Tools by DareDev
• 6,890 points
792 views
+1 vote
1 answer

What is the difference between JavaScript and Java

This quote rightly explains that 2 totally ...READ MORE

answered Jun 29, 2018 in Java by Daisy
• 8,120 points
241 views
0 votes
1 answer

Set cellpadding and cellspacing in CSS?

For controlling "cellpadding" in CSS, you can ...READ MORE

answered Jun 10 in CSS by Edureka
• 8,460 points
9 views
0 votes
1 answer

Why vh works and % doesn't? (height css)

The height of an element, by default, ...READ MORE

answered Jun 10 in CSS by Edureka
• 8,460 points
13 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP