Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to change background color by click using Javascript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 510
    Comment on it

    Hello Reader's if you want to change css of any div or section or iframe with just a single click then javascript offers you to do this in real time. Lets see how to change background color of an ifram using just a single click

    <iframe src="JavaScript:'content'" style="height:100px"></iframe>
    
    <input type="button" onclick="ChangeBGColor()" value="click me">
    

    In the code above the button will change the background color of Iframe when clicked.

    Now the JS for this event will go like this:-

    <script>
      function ChangeBGColor() {
        var iframe = document.getElementsByTagName('iframe')[0]
        var doc = iframe.contentWindow.document
        doc.body.style.backgroundColor = 'green'
      }
    </script>
    

    Now on loading the page when user will click the button.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: