Q15

Question 15

Write a java script

a. To change the colour of text using SetTimeOut()

b. To move an image across screen using SetInterval()

circle-info

a. Taking Color value from user via click and prompt and then changing color value.

b. Placed a box on screen using CSS and added Image element in that and wrote Javascript function to increment co-ordinates and displace image.

Browse Code Herearrow-up-right

Code

<html>
   <head>
      <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
      <title>
      Change My Colour | Javascript 3 (a. Part)
      </title>
   </head>
   <script language="javascript">
      function my_function() {
      	setTimeout('ppp()',1000);
      }
      
      function ppp() {
      	var colorvalue=prompt("Enter Color","Blue");
      	document.getElementById("block").setAttribute(
      "style","color:" +colorvalue);
      }
   </script>
   </head>
   <body>
      <center>
         <div class="container">
            <div class="container-fluid mt-5">
               <h1>Change My Colour 
               | Javascript 3 (a. Part)</h1>
            </div>
            <div class="container mt-5" id ="block">
               <h3>Change My Text Color</h3>
            </div>
            <div class="container mt-3">
               <input type="button" 
               value="Change Colour" 
               name="b" 
               onClick="my_function()">
            </div>
         </div>
      </center>
   </body>
</HTML>
Download javascript_3_a.html

Output

Main Page (1/5)
On Tapping Change Colour Buttton (2/5)
Text Turned To Blue (3/5)
Text Colour Input To Red (4/5)
Text Colour Changed To Red (5/5)
circle-check
Live Demo javascript_3_a.html
Live Demo javascript_3_b.html

Last updated