Facebook Like Button

Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

JavaScript

Till now, we were practicing Inline Scripting. i.e.(Script inside Body Tag)
This is the first example showing Internal Scripting. i.e.(Script inside Head Tag)
You can't see this script here live, due to certain limitations of Google. You have to save it in a HTML file and run it.
Here, I used a predefined method "setInterval("fnname_to_be_recalled",time_in_ms)".


Code:
<html>
<head>
<script type="text/javascript">
var i=0;
function blink() {
if(i==0){
idp.style.color="white";
i=1;
}
else{
idp.style.color="black";
i=0;
}
}
function repeat(){
setInterval("blink()",100);
}
</script>
</head>

<body onload="repeat()">
<div id="idp">Blinking Text</div>
</body>
</html>

JavaScript

This script shows you the way functions are used in JavaScript. The following script shows you:
  • How to declare functions.
  • How to call the functions you have declared.
  • How to change CSS properties of an element with js.
  • The use of inbuilt function alert().

Click me to run this Script.


Script & HTML Code:
<body>
<p id="idp"onclick="alertfn()" onmouseover="mpointer()">
<b><u>Click me to run this Script.</u></b>
</p>
<script type="text/javascript">
<!--
function alertfn(){
alert("This is the Alert box!!!\nClick OK or CLOSE the window to go back!!");
}
function mpointer(){
idp.style.cursor="pointer";
}
-->
</script>
</body>

JavaScript

I am thinking of practicing JavaScript, so lets get started...
If the time is less than 10, you will get a "Before 10am" greeting. Otherwise you will get a "After 10am" greeting.
You need to enclose this script inside script tag.
You need to visit this page at different times to confirm that my script is working well or you can change time of your System.

JavaScript:
var d = new Date();
var time = d.getHours();
if (time < 10) { document.write("Before 10am"); } else { document.write("After 10am"); }

OUTPUT: