Home > Web Front-end > JS Tutorial > body text

jquery plug-in learning (3)_jquery

WBOY
Release: 2016-05-16 17:51:05
Original
892 people have browsed it

For example:

Copy code The code is as follows:

$(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.
Copy code The code is as follows:

$('body *').click(function( ){
$(this).test().html(this.nodeName).hide(1000);
});
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template