Please see this fiddle:
HTML:
<div id="papa" onclick="anything(this);">Blabla</div>
JS:
function anything(theObj){
window.alert(theObj.innerHTML);
}
I do not understand why the function “anything” gets as not reconized. (using prototype)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It is not that it doesnt recognide
this– it does not recognise the methodanythingbecause of a setting you’ve made in jsfiddle – to scope the javascript intoonLoad. If you would have chosenno wrap (head)it would work fine: http://jsfiddle.net/GSHsH/11/A bit more detail. The way you set it up, this is what gets injected into the output frame in jsfiddle:
Note that the method
anythingis not in global (window) scope, it is in the scope of a particular function. This means its not visible to the element on the page.The way I set it up you get this:
Which is just a plain old function defined in the head of the page – now accesible from an element on the page.