Flash Games
 FAQ   Search   Memberlist   Usergroups   Register  Profile   Log in to check your private messages   Log in 


Change Element's className



 

Post new topic   Reply to topic  
   DEVPPL Forum Index -> Script-archive
View previous topic :: View next topic  
Author Message
rangana
250+ Club


Joined: 27 Feb 2008
Posts: 271
Location: Cebu City Philippines

PostPosted: Wed Apr 23, 2008 6:12 am    Post subject: Change Element's className Reply with quote

This script enables you to change the className of any element Smile
Code:

<script type="text/javascript">
window.onload = function()
{
   var obj=document.getElementById('link').getElementsByTagName('a');
   for(var start=0;start<obj.length;start++)
      {
      obj[start].onclick=function()
         {
         this.className = (this.className != 'on')? 'on': 'off';
         }
      }
}
</script>


It's full implementation could be best explained with a complete script Wink
Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
a{display:block;width:100px;line-height:30px;color:#2d2d2d;font-family:Tahoma;font-size:10pt;margin:1px;text-align:center;}
#link{width:104px;margin:10px auto;border:3px double #2d2d2d;padding:10px;}
  .on  {background-color:#9c0;}
  .off {background-color:#69c;}
</style>
<script type="text/javascript">
window.onload = function()
{
   var obj=document.getElementById('link').getElementsByTagName('a');
   for(var start=0;start<obj.length;start++)
      {
      obj[start].onclick=function()
         {
         this.className = (this.className != 'on')? 'on': 'off';
         }
      }
}
</script>
</head>
<body>
<div id="link">
  <a href="#" id="link_111" class="on">On</a>
  <a href="#" id="link_222" class="off">Link 2</a>
  <a href="#" id="link_333" class="off">Link 3</a>
</div>

</body>
</HTML>
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    DEVPPL Forum Index -> Script-archive All times are GMT + 1 Hour
Page 1 of 1

 
 
Welcome to DEVPPL.com
You are not logged in, which means that you can't post in the forums.
Click here to Register

If you are a current member here on DEVPPL, please login below:

User: Pass:
Log me on automatically each visit:

 


Powered by phpBB © 2001, 2005 phpBB Group - Modified by DEVPPL

Flash Games - Sitemap