For example:
$(this).test().hide ().height();
To achieve similar concatenation behavior, you should return a jquery object in each plug-in method, unless the method requires an explicit return 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 result of the iteration. For the example in the previous section, further modify
jQuery.fn .test = function(){
return this.each(function(){ //Traverse the matching elements, this here represents the object collection
alert(this.nodeName); // Prompt the current jquery object DOM node name
})
}
Then, we can write the behavior in the application example. For example, in the following example, a message prompting the name of the node will pop up first. , then use the current node name to rewrite the information contained in the current element, and finally slowly hide the element.
$('body *').click(function( ){
$(this).test().html(this.nodeName).hide(1000);
});