Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] onclick - unobtrusive javascript


  • From: lester at denhaag.org (J. Lester Novros II)
  • Subject: [Javascript] onclick - unobtrusive javascript
  • Date: Sat Jul 23 04:48:25 2005

Tim Burgan wrote:
> When an element is clicked, I am unable to change it's text color to red.
> But for the same element, the code does work if I choose to open a new 
 > window on click.

The 'i' within the anonymous function assigned to each link's onclick handler is 
never resolved to a number since by the time you actually click on the link, the 
program has exited the for loop. Try using 'this.style.color' instead [see below].

   function doPopups()
   {
      if ( !document.getElementsByTagName )
         return false;

      var links = document.getElementsByTagName("a");
      for ( var i = 0; i < links.length; i++ )
      {
         if ( links[i].className.match("change") )
         {
            links[i].onclick =
            function()
            {
               this.style.color = 'red';
               return false;
            }
         }
      }
   }

l8R lES
-- 
"Anti-virus products for Unix servers occupy a useful niche in the market, not
because there are many viruses that infect Unix platforms but because they help
prevent these servers from hosting Windows malware."  John Leyden - the Register
                                                           http://www.denhaag.org