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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay