[thelist] Unobtrusive JavaScript & return false

Matt Warden mwarden at gmail.com
Mon Jul 24 00:06:17 CDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Hi Paul,

Paul Bennett wrote:
> Hi all,
> 
> Can anyone using the YIU JS library tell at a glance why this isn't working? 
> By which I mean that the functions specified in the function component of the onclick handler are working (eg. functionOne) but return false isn't.

First of all, there is an *excellent* discussion list specifically for
the YUI library. You can find it on the YUI site:
http://developer.yahoo.net/yui


> ------
> YAHOO.util.Event.addListener(fliplink, "click", function(){ functionOne(); return false; });
> -------
> 
> The only way I seem to be able to get return false to work is like this:
> 
> -------
> Fliplink.onclick = function(){ functionOne(); return false; };
> -------
> 
> But then I lose the ability to use the 'this' keyword in the functions preceding the return false statement.
> 
> Any help welcome, happy to provide more info / code if required.

I assume you are trying to stop the event. return false is not the way
to do this. The reason it does not work in addListener is because
addListener uses attachEvent or addEventListener if they are available
in the browser. You want to take a look at preventDefault,
stopPropagation, or stopEvent (which does both), depending on exactly
what you're trying to do:

http://developer.yahoo.com/yui/docs/event/YAHOO.util.Event.html#preventDefault
http://developer.yahoo.com/yui/docs/event/YAHOO.util.Event.html#stopPropagation
http://developer.yahoo.com/yui/docs/event/YAHOO.util.Event.html#stopEvent


- --
Matt Warden
Cleveland, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFExFVJrI3LObhzHRMRAlqdAJ9TyxbHtSCrtPshe7FobFriq45l0QCgqcQA
GRR5WCdMz2wPH/wFwULQytk=
=goQ8
-----END PGP SIGNATURE-----



More information about the thelist mailing list