jQuery.prototype.test=function(){
this. css("color","#99");//This here is a jquery object, not a dom object
alert(this[0]);//This[0] here refers to the dom node object
}
$( "body").click(function(){
$(this).test();
$(this).test().html(this.nodeName).hide(10000);
})
When using the click method on the page, it is equivalent to creating a new Jquery object and then calling its click method. The parameter in the method is a javascript function, and this inside refers to JavaScript object, this is the syntax keyword of JavaScript itself. It points to a JavaScript object, so you can use the method
owned by the pointed target JavaScript object. And jQuery.prototype.test is equivalent to the query object. Create a new test method, so the this inside should be the jquery object
. Through this[0], the jquery object can be converted into a dom node object
because this always points to the calling method (function ) of the object (except call and apply methods)