JavaScript Examples

A few simple JavaScript examples are provided here.

Changing font weight when mouse cursor is moved over object

The following example modifies text to bold when the mouse is moved on top of it. Here's the code:

<P ID="boldpara1" onmouseover="javascript:document.all.boldpara1.style.fontWeight= 'bold'" onmouseout="javascript:document.all.boldpara1.style.fontWeight='normal'" >
This text will turn bold when the mouse cursor is placed on it.
</P>

Here's how it looks:

This text will turn bold when the mouse cursor is placed on it.

Making text background change

This example changes the background of the text every half second. Here's the code"

<P ID=bgchange STYLE="background-color: 0000ff">
The background changes every half second
</P>

<SCRIPT LANGUAGE="JavaScript">
function turn_red()
{
bgchange.style.backgroundColor="ff8080";
greenTimer=setTimeout("turn_green()", 500);
}

function turn_green()
{
bgchange.style.backgroundColor="80ff80";
blueTimer=setTimeout("turn_blue()", 500);
}

function turn_blue()
{
bgchange.style.backgroundColor="8080ff";
redTimer=setTimeout("turn_red()", 500);
}

turn_red();
</SCRIPT>

Here's how it looks:

The background changes every half second