Make a background disappear on user input, change its background to red - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Form Event

Description

Make a background disappear on user input, change its background to red

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
   </head> 
   <body> 
      <input type="text" style="background: green" onkeyup="modifyBackground(this)"> 
      <script type="text/javascript">
function modifyBackground(elem){/* w  ww. j a v a2  s . c o  m*/
    if( elem.value !== "" ){
        elem.style.background = "red";
    } else {
        elem.style.background = "green";
    }
}

      </script>  
   </body>
</html>

Related Tutorials