At first, I thought that this and $ (this) were carved out. But when I was reading, I found that coding was not the same thing.
What is "this "?
In jsonobject-oriented
Programming versions, this (or self) is a keyword which can be used in
Instance methods to refer to the object on which the currently executing
Method has been invoked.
$ ( " # Textbox " ). Hover (
Function (){
This . Title = " Test " ;
},
Fucntion (){
This . Title = " OK ";
}
);
Here this is actually an HTML element (textbox). textbox has the text attribute, so there is no problem in writing this.
But if you replace this with $ (this), that's not the case.Error -- reported.
error code:
$ ("# textbox "). hover (
function () {
$ (this ). title = "test";
},
function () {
$ (this ). title = "OK";
}
);
Here$(This) is a jquery object, and the jquery object does not have the title attribute. Therefore, this write is incorrect.
Jquery has the ATTR () method that can get/set the attributes of DOM objects, so the correct syntax should be as follows:
correct Code :
$ (" # textbox "). hover (
function () {
$ (this ). ATTR ('title', 'test');
},
function () {
$ (this ). ATTR ('title', 'OK');
}
);
the advantage of using jquery is that it includes operations performed on DOM objects by various browser versions, so $ (this) is used in a unified manner) it should be a good choice to stop using this.