H
hobosalesman
Consider the following (where 'a' is an anchor element with a valid URL
href):
a.onclick=help_mode;
function help_mode() { alert("hi"); return false; }
As expected clicking on the link now results in a "hi" but no change in
location, the link isn't followed because onclick returned false. Now
look at what I thought was the same thing:
a.addEventListener('click', help_mode, false);
function help_mode() { alert("hi"); return false; }
Clicking on the link now results in "hi" and then the link is loaded!
Can anyone explain what the difference is, that the return value of
false is ignored when addEventListener is used?
I'm trying to disable links for every anchor on the page with
javascript, and instead launch a "help" window based on the title
attribute of the tag. In other words, a help mode where the user can
click on the element they want help with, but I don't want the location
to change when in help mode.
HS
href):
a.onclick=help_mode;
function help_mode() { alert("hi"); return false; }
As expected clicking on the link now results in a "hi" but no change in
location, the link isn't followed because onclick returned false. Now
look at what I thought was the same thing:
a.addEventListener('click', help_mode, false);
function help_mode() { alert("hi"); return false; }
Clicking on the link now results in "hi" and then the link is loaded!
Can anyone explain what the difference is, that the return value of
false is ignored when addEventListener is used?
I'm trying to disable links for every anchor on the page with
javascript, and instead launch a "help" window based on the title
attribute of the tag. In other words, a help mode where the user can
click on the element they want help with, but I don't want the location
to change when in help mode.
HS