Change div text by checking its old value - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Div

Description

Change div text by checking its old value

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){//from www . ja  v a2 s  .com
var div1 = document.getElementById('div1');
    var div2 = document.getElementById('div2');
    if (div1.innerHTML == 'YES') {
        div2.innerHTML = 'new value';
    }else{
        div2.innerHTML = 'new value 1';
    }
}

      </script> 
   </head> 
   <body> 
      <div id="div1">
         YES
      </div> 
      <div id="div2"></div>  
   </body>
</html>

Related Tutorials