[thelist] onclick - unobtrusive javascript
Matt Warden
mwarden at gmail.com
Fri Jul 22 23:44:33 CDT 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Tim Burgan wrote:
> Is there any particular reason why I can't get this to work? My code is
> attached below.
links[] has no validity in the scope of the function object you are
assigning to the onclick handler. Remember, the function() {} notation
is basically just shorthand for:
function myfunc()
{
// this line works
window.open(this.href);
// this line does not
links[i].style.color = 'red';
return false;
}
function doPopups()
{
// ...
links[i].onclick = myfunc;
// ...
}
In this instance it is clearer how the links array is not in scope of
myfunc. Try using a reference to 'this'. See:
http://www.quirksmode.org/index.html?/js/this.html
hth,
- --
Matt Warden
Miami University
Oxford, OH, USA
http://mattwarden.com
This email proudly and graciously contributes to entropy.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFC4csxAQ0d4HGyPE8RAonVAJ9T1N0NZNO5HRAPD4ZRdnmGHOeyBQCfS3I/
RA0hZWZn+3V5tVs5jzfPYFk=
=Wnpn
-----END PGP SIGNATURE-----
More information about the thelist
mailing list