Hey guys, I need some JavaScript help.
In this JavaScript application I was stopping the browser from following the href like so (the "return false;" is what stops the link):
Since putting JavaScript inline with HTML markup is a giant NO NO, I am using a JavaScript eventListener instead. Like so:
However, the "return false" is no longer working while in the eventListener. Anyone know what is wrong?
For now I am just replacing the href with '#', like below, but there must be a better solution.
In this JavaScript application I was stopping the browser from following the href like so (the "return false;" is what stops the link):
Code:
<a href="http://www.apple.com" id="appleLink" onclick="someFunction(); return false;">Random Test</a>
Since putting JavaScript inline with HTML markup is a giant NO NO, I am using a JavaScript eventListener instead. Like so:
Code:
var appleLink = document.getElementById('appleLink');
appleLink.addEventListener('click', appleMenuItemClicked, false);
function appleMenuItemClicked() {
// lots of javaScript here
return false;
}
However, the "return false" is no longer working while in the eventListener. Anyone know what is wrong?
For now I am just replacing the href with '#', like below, but there must be a better solution.
Code:
function appleMenuItemClicked() {
// lots of javaScript here
this.href='#';
}