Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
In the following code, what is 'this' referring to.?
Is it referring to the node that was just appended to vacation?
3 Answers
- ChrisLv 76 years agoFavorite Answer
$(x).on('click', y);
sets y as click handler for x. The actual JavaScript code is
document.querySelector( "button" ).onclick = function() {
...// "this" is used in here
};
Since onclick is a member of the button object, "this" refers to the button.
- JasonAmazingLv 56 years ago
This piece of code executes upon complete page load. It sets on click function for the button.
Once you click the button it would set element,probably div with id vacation, to text 'From 399' and then remove the button so it can't be clicked again
- dewcoonsLv 76 years ago
In Java, "this" is used to refer to whatever object currently has the "focus" in the program. In the code that you gave, it would be the button that was selected in the line before.
Often when you are in a subroutine you have no way of knowing what object will be selected. "This" means uses what the current object is. You have to backtrack in the code to determine what "this" is.