DEV Community

Cover image for Using DOM manipulation to style an element in JavaScript
Amara Nechey
Amara Nechey

Posted on

3 2 1 1 1

Using DOM manipulation to style an element in JavaScript

Hello guys, in this my article which is my first here, I will be using JavaScript to change the colour of an element using DOM MANIPULATION.
DOM manipulation is simply document object model manipulation, it has to do with changing styles, texts, contents on a page using JavaScript.

Changing HTML Style

To change the style of an HTML element, use this syntax:

document.getElementById(id).style.property = new style
Enter fullscreen mode Exit fullscreen mode
  • Example
<html>
<body>

<p id="p2">Hello World!</p>

<script>
document.getElementById("p2").style.color = "blue";
</script>

</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Happy coding!

Top comments (0)

Neon image

Next.js applications: Set up a Neon project in seconds

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Get started →

👋 Kindness is contagious

Dive into this thoughtful article, cherished within the supportive DEV Community. Coders of every background are encouraged to share and grow our collective expertise.

A genuine "thank you" can brighten someone’s day—drop your appreciation in the comments below!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found value here? A quick thank you to the author makes a big difference.

Okay