For example:
Copy codeThe Code is as follows:
$ (This). test (). hide (). height ();
To implement similar writing behavior, a jquery object should be returned in each plug-in method unless the method needs to explicitly return a value. The returned jquery object is usually the object referenced by this. If you use the each () method to iterate this, you can directly return the iteration result. For the example in the previous section, modify
Copy codeThe Code is as follows:
JQuery. fn. test = function (){
Return this. each (function () {// traverses matched elements. this indicates the object set.
Alert (this. nodeName); // prompt the dom node name of the current jquery object
})
}
Then, we can perform the write operation in the application example. For example, in the following example, a message indicating the node name is displayed, then, use the current node name to overwrite the information contained in the current element, and hide the element slowly.
Copy codeThe Code is as follows:
$ ('Body * '). click (function (){
Certificate (this).test().html (this. nodeName). hide (1000 );
});