Using Switch case to set various value for <p> - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Paragraph

Description

Using Switch case to set various value for <p>

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <p id="para1"></p> 
      <script>
var i = 3;
switch(i){/*from  w w w .j av a  2s  .c  o m*/
case 1: {
   document.getElementById('para1').innerHTML = "The value is one.";
   break;
}
case 2: {
   document.getElementById('para1').innerHTML = "The value is two.";
   break;
}
case 3: {
   document.getElementById('para1').innerHTML = "The value is three.";
   break;
}
default:{
   document.getElementById('para1').innerHTML = "The value is undefined."
}
}

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

Related Tutorials