<input type=”button” value=”modify” οnclick=”changeContent()”>
The function changeContent written in onclick on the element is equivalent to calling the function directly. The this used in the function points to the global object window,
instead of pointing to the element
Then to get the object of the node where the onclick is located, we need to pass this when calling the function:
<input type=”button” value=”modify” οnclick=”changeContent(this)”>
Here this refers to the input tag, and $(this) turns it into a jq object;
function changeContent(e){
var _this = $(this)
}
…
The post this points to the problem with binding onclick events on the label this points to the problem first appeared on Lenix Blog .
This article is reprinted from https://blog.p2hp.com/archives/9067
This site is for inclusion only, and the copyright belongs to the original author.