How to change the background color using JavaScript?

How to change the background color using JavaScript?


1. To Change the entire web page background color use below code
          document.body.style.backgroundColor ="#000"

2.  Change the background color of an element using ID

         <p id="MyParagraph">Hiiii..How are you?</p>

        <script type="text/javascript">
               $(window).on("load", function() {
                   document.getElementById("MyParagraph").style.backgroundColor="red";
            });
        </script>



                                                                                                                                -Happy Coding

Comments

Popular posts from this blog

Validation Code For Phone Number Using preg_match() in Php

Writing data to a file using Python

Update and Delete Record Using PHP and MySQL