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

What are the common methods of jquery

清浅
Release: 2019-02-27 15:22:44
Original
5520 people have browsed it

Commonly used methods in jQuery include the add method for adding elements, the not method for removing a specified collection, the map method for matching elements and returning a new object, the each method for traversing an array or object, the append method for adding content at the end of an element, etc.

There are many different methods in jQuery to help us achieve various functions. Next, in the article, we will introduce some commonly used methods in jQuery, which have certain reference value. I hope it will be helpful to everyone

What are the common methods of jquery

【Recommended course: jQuery Tutorial

(1) add() method

$("selector").add(selector1[,context]);
Copy after login

The add() method is to add the selectior1 element to the matching element collection, where the selector1 element can be a jQuery object, DOM object and HTML tag. The optional parameter context specifies the location where the context is to be inserted. This method has the opposite effect to the not() method

(2)not() method

$("selector").not(expr);
Copy after login

not() method is used to remove from the matching selector element set The specified set, expr can be a selector or a function. If it is a selector, the set matching expr will be removed from the selector set; if expr is a function, the current set will be removed only when the function returns true. The jQuery object corresponding to the index

(3) map() method

$("selector").map(callback(index,domElement)); 
Copy after login

The map() method is used to pass each element in the current matching element collection into the callback function and returns a new jQuery object. This method is equivalent to reorganizing the contents of the matching set. where index is the element index, and domElement is the jQuery object corresponding to the current index.

(4)each() method

$.each(object,callback(indexInArray,valueOfElement));
Copy after login

each() method is used to traverse the object array or object, where callback is the callback function. This method needs to be noted that $.each() method can traverse all arrays, while $("selector").each(function(){}); can only traverse jQuery Object array

(5) extend() method

$.extend(target,object1);
Copy after login

extend() method means merging the contents of two or more objects into the first In the object target, to implement the expansion of the first object and return the modified object

(6) append() method

$(selector).append(content)
Copy after login

append() method is mainly used Insert specified content at the end of the selected element

(7) delegate() method

$(selector).delegate(childSelector,event,data,function)
Copy after login

delegate method is mainly used to add response events to the added elements, where childSelector represents one or more child elements with attached event handlers; event represents one or more events attached to the element, with multiple event values ​​separated by spaces. Must be a valid event. data is an optional parameter used for additional data passed to the function

(8) isEmptyObject() method

$.isEmptyObject(object);
Copy after login

isEmptyObject() method is used to determine an object Whether it is empty, that is, the object does not contain any attributes. If it is empty, it returns true

Summary: The above is the entire content of this article, I hope it will be helpful to everyone.

The above is the detailed content of What are the common methods of jquery. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!