swap / pertukaran css class onclick javascript

<style type="text/css">
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";



<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>



Published by


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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s