Learn free online HTML5, javascript, and jquery Tutorials by Examples

Friday, 13 June 2014

Changing the background color based on user input in javascript

----------------------------------------------------------
<input type="button" value="blue" id="change color" onclick="changecolor()" />
<input type="button" value="green" id="undo color" onclick="undocolor()" />

<script>
    //document.body.innerHTML = 'satish'
    var oldcolor = 'black';
    function changecolor(){
            var oldcolor = document.body.style.backgroundColor;
            var newcolor = prompt('Enter Your Color');
            document.body.style.backgroundColor = newcolor;
        }
       
        function undocolor(){
            var newcolor = oldcolor;
            oldcolor = document.body.style.backgroundColor;
            document.body.style.backgroundColor = newcolor;
        }
       
</script>

----------------------------------------------------------

No comments:

Post a Comment