DEV Community

Himanshupal0001
Himanshupal0001

Posted on

DOM for beginners #4

CSS styling in Js

We can also style element of html from css.

<body>
    <h1 id="h1id1">This is first heading</h1>
    <h1 id="h1id2">This is second heading</h1>

    <!--             script               -->

    <script>
        document.getElementById('h1id1').style.color='red';//for single line styling

        document.getElementById('h1id2').setAttribute("style", 'color:red; background: green; text-align:center; border-radius: 2rem; border: 1rem solid black');

    </script>
</body>

Enter fullscreen mode Exit fullscreen mode

Top comments (0)