简体   繁体   中英

I'm to change color of <div> in javascript on mouseOver function.Where am i going wrong?

sharing the code
Help me with the solution

<div id ="hus" onmouseover="mouseOver()" style="background-color:#00FFFF;width:120px;height:20px;padding:40px;"> HUSAIN </div>

    <script>
    function mouseOver() {
      var x = document.getElementById( "hus" );
      x.style.backgroundColor = "red";
    }
    </script>

where am i going wrong????

Your codes actually work. If you mean the font-color, add this - (x.style.color = "blue";). There's nothing wrong with your syntax. But if it's with file extension, make it's ".html".

I'm sorry. My previous answer is incorrect. Your syntax should be like this:

For the background: x.style.background = "red";

For the color of the text/font: x.style.color = "blue";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM