Search This Blog

Tuesday, June 19, 2012

Day 6 js Demo

<script type="text/javascript">
  var a=8;
  //document.write("<br/><b class=\"alignright\">keep your mouth shut.</b><br/>");
  if (a==='8')
   document.write(a);

  function displayAlert(){
   alert('this is a link');
  }

  function printIt(text){
   var i=0;
   for(i=0; i<text.length; i++){
   document.write("<span style=\"color:" + randomColorCode() + ";\">" + text[i] + "</span>");
    //html:<span style="color:#343434;">wifi</span>
    document.write("&nbsp;");
   }
  }

  function randomColorCode(){
   var colorCode = 0;
   colorCode = Math.floor(Math.random()*1000000);
   if (colorCode<100000)
    colorCode = colorCode + 100000; 
   return "#" + colorCode;
  }
  
  
 </script>

//call function (inside html body if the content is to be displayed in your html doc)

<script type="text/javascript">
 printIt("text");
 </script>
 <a href="#" onclick="displayAlert();"><img src="../images/sample.jpg" width="20%"/></a>

No comments:

Post a Comment