SGMLXML.net A place for SGML and XML application developers.

December 20, 2005

Toggle colors on html span element using Javascript

Filed under: CSS,DOM,XSLT — cangione @ 11:31 pm

Javascript for changeing the color of span elements with a particular class attribute.

<script type="text/javascript">
function changecolor() {
for (i=0;i<document.getElementsByTagName("span").length; i++) {
if (document.getElementsByTagName("span").item(i).className == "myclass"){
document.getElementsByTagName("span").item(i).style.color = "green";
}
}
}
</script>

.......

<a href="#" onclick="changecolor();">Change Color</a>

.......

<span class="myclass">Hi There</span>

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.

Powered by WordPress