DEV Community

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

Posted on

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)