swap / pertukaran css class onclick javascript

<html><head><title></title>
<style type="text/css">
<!--
    .red{background-color:red;color:#000000;}
    .green{background-color:green;color:#000000;}
-->
</style>
<SCRIPT>
function show(id)
{
    var anchorTags = document.getElementsByTagName("a");
        for (var i = 0; i < anchorTags.length ; i++)
        {
            anchorTags[i].className= "red";
        }
    document.getElementById(id).className=  "green";
}

    </script>

</head><body>

<a class=red href="#" id=link1  onclick="show('link1')">Link1</a>
<a class=red href="#" id=link2 onclick="show('link2')">Link2</a>
<a class=red href="#" id=link3 onclick="show('link3')">Link3</a>

</body></html>

Published by

G3n1k

just to remember what i had known :)

One thought on “swap / pertukaran css class onclick javascript”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s