Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140734

How to change div color from a given value in JavaScript

$
0
0
<div id="nav">
    Some Text
</div>

<input type="text" id="color"><button onClick="changeColor()">Change</button>

<script>

    function changeColor(){

        var colorCode = document.getElementById('color').value;
        var  nav = document.getElementById('nav');

        nav.style.background = "'"+colorCode+"'";
    }

</script>

When i enter for ex.: red in the input field and than press the button, nothing happens.


Viewing all articles
Browse latest Browse all 140734

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>