The className Property
A class name is an identifier that is assigned to the class attribute of an element. To associate a CSS rule with several elements in a document assing the same identifier to the class attributes of those elements, and use that identifier as the CSS rule’s selector. An element’s className property enables the application of different CSS rules to that element under script control.
Code:
<html>
<head>
<title>The className property</title>
<style type="text/css">
.newstyle{font-size:16pt;color:red}
</style>
<script type="text/javascript">
function toggleStyle(ID)
{
var elem = (document.all) ? document.all(ID) : document.getElementById(ID);
if(elem.className == "")
{
elem.className = "newstyle";
}
else
{
elem.className = "";
}
}
</script>
</head>
<body>
<form>
<input type="button" value="toogle" onClick="toggleStyle('article1')" />
</form>
<h1>Article 1</h1>
<p id="article1">Greece Hellas, officially known as the "Hellenic Republic" is the southeastern most country in Europe, occupying the southernmost part of the Balkan Peninsula.
It is bordered by Albania, X-Yugoslavia (the Republic of Skopje) and Bulgaria from the north, and the European part of Turkey from the northeast.
From the east by the Aegean Sea, from the south by the Mediterranean Sea, and from the west the Ionian Sea, including more than 400 islands,
which occupy more than one fifth of its total land territory the total area of the country is 131,957 square kilometers (50,949 square miles).</p>
<h1>Article 2</h1>
<p>The mainland portion of Greece comprises the regions of Thraki and Macedonia in the north;
Epirus, Thessaly, and Central Greece in the central section; and in the south Peloponnisos, a peninsula which is connected to the rest of the mainland by the Isthmus of Corinth.
The remainder of Greece consists of more than 400 islands, (only 149 are inhabited.)
These are Evia, Crete, or Kriti, the Northern Sporades, the Cyclades, the Dodecanisa, Chios, Limnos,
Lesvos, Samos, Samothraki, and Thassos, all of which are spread out in the Aegean Sea. In the west,
the Ionian Sea, is where the Eptanisa are found, a group of seven inhabited major islands and three small uninhabited ones.</p>
</body>
</html>
Save this code as class_name.html
Leave a Reply
You must be logged in to post a comment.
