I'm kind of curious why this doesn't work
JavaScript:
function evaluate(){
console.log(42);
}
HTML:
<a onclick="evaluate()">Click Me!</a>
Is evaluate a reserved keyword somewhere on the html side?
I'm kind of curious why this doesn't work
JavaScript:
function evaluate(){
console.log(42);
}
HTML:
<a onclick="evaluate()">Click Me!</a>
Is evaluate a reserved keyword somewhere on the html side?
"evaluate" is not a reserved keyword, but when it's used in inline event handler, it happens to collide with document's evaluate
function(document
object is within handler's scope chain before the window
object). If you don't want to change your function name, just add window
context before it, i.e.
<a onclick="window.evaluate()">Click Me!</a>
document.evaluate
is needed for parsing XMLs, see the reference in the MDN here.
Evaluate is not a reserved word in JavaScript, document.evaluate
is used to evaluate XPath expressions.
You could still name your function evaluate
if you used a less obtrusive method of attaching your event handler:
var evaluate = function (){
console.log(42);
}
document.addEventListener('click', evaluate, false);