Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)
Can anyone help to create and style div using JavaScript?

1 Answer

0 votes
by (26.7k points)

You can use the below code to achieve that:

var div = document.createElement("div");

div.style.width = "100px";

div.style.height = "100px";

div.style.background = "red";

div.style.color = "white";

div.innerHTML = "Hello";

document.getElementById("main").appendChild(div);

I hope this will help.

Want to become a Java Expert? Join Java Training now!!

Want to know more about Java? Watch this video on Java Tutorial | Java Course | Java For Beginners:

Related questions

0 votes
1 answer
asked Mar 16, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
0 votes
1 answer
asked Apr 10, 2021 in Web Technology by Jake (7k points)
0 votes
1 answer
asked Apr 13, 2021 in Java by dante07 (13.1k points)

Browse Categories

...