javascript - Why can't I call this object's function from an in-line anchor? -


html:

<a href="javascript:alert('hey.')">alert</a><br/> <a href="javascript:alert('in anchor:\n' + objection.sustained());">alert</a> 

javascript:

var objection = {     sustained : (function() {return ("accroches-toi ton reve")}) };  alert("in script: \n" + objection.sustained());  $("outdat").text( +"<br/>\n"); 

working sample

just curious here, why can't call objection.sustained() anchor tag, it's ok script region?

it seems not know object exists when using anchor. happens in several major browsers believe design?

variable scope.

fiddle placing variable in document load scope you're anchor code can not see it. @kjy112 mentioned, remove code blocks , should work fine.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -