0

As i understand when we invoke a method this contains reference to object which invoke this method. But what is an "object" and a "method" in the following case:

Consider html code snippet

<div id="parent">
 <input type="submit" id="submit" value="submit" onclick="doThis(this)"/>
</div>

where doThis() is JS function, such that

doThis(obj){
 obj.style.background="#ff00ff"
}

I know, that this will be contained reference to submit button, but i dont understand why.

asked Dec 15, 2013 at 19:07
3

1 Answer 1

3

See the HTML 5 specification:

When an event handler content attribute is set

...

create a function object (as defined in ECMAScript edition 5 section 13.2 Creating Function Objects)

...

Set the corresponding event handler to the aforementioned function

and

Process the Event object E as follows:

...

Invoke callback with one argument, the value of which is the Event object E, with the callback this value set to E's currentTarget.

answered Dec 15, 2013 at 19:20
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.