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
【Recommended course: jQuery Tutorial】
(1) add() method
$("selector").add(selector1[,context]);
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);
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));
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));
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);
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)
append() method is mainly used Insert specified content at the end of the selected element
(7) delegate() method
$(selector).delegate(childSelector,event,data,function)
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);
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!