List of common jquery methods (SET)

Source: Internet
Author: User
Tags getscript

Classic Summary of common jquery Methods

Attribute:
$ ("P"). addclass (style type defined in CSS); add a style to an element
$ ("IMG"). ATTR ({SRC: "test.jpg", alt: "Test image"}); add attributes/values to an element. The parameter is map.
$ ("IMG"). ATTR ("src", "test.jpg"); add attributes/values to an element
$ ("IMG"). ATTR ("title", function () {return this. SRC}); add attributes/values to an element
$ ("Element name" ).html (); obtain the content (elements, text, etc.) in the element)
$ ("Element name" ).html ("<B> new stuff </B>"); set content for an element
$ ("Element name"). removeattr ("attribute name") deletes a specified attribute and its value for an element.
$ ("Element name"). removeclass ("class") deletes a specified style for an element.
$ ("Element name"). Text (); get the text of this element
$ ("Element name"). Text (value); set the text value of this element to value
$ ("Element name"). toggleclass (class) cancels when the element has a style in the parameter. If it does not exist, set this style.
$ ("Input element name"). Val (); get the value of the input element
$ ("Input element name"). Val (value); set the value of the input element to value
Manipulation:
$ ("Element name"). After (content); add content after the Matching Element
$ ("Element name"). append (content); insert content as the element content to the end of the element
$ ("Element name"). appendto (content); Add the element after the content
$ ("Element name"). Before (content); opposite to the After Method
$ ("Element name"). Clone (Boolean expression) when the Boolean expression is true, the cloned element is treated as true if no parameter exists)
$ ("Element name"). Empty () sets the content of this element to null
$ ("Element name"). insertafter (content); insert the element to the content
$ ("Element name"). insertbefore (content); before inserting this element into content
$ ("Element"). prepend (content); Use content as a part of the element and place it at the beginning of the element.
$ ("Element"). prependto (content); Use this element as a part of content and put it at the beginning of content
$ ("Element"). Remove (); Delete all specified elements
$ ("Meta"). Remove ("exp"); Delete all elements containing exp
$ ("Element"). Wrap ("html"); Use HTML to enclose this element
$ ("Element"). Wrap (element); Use element to enclose this element
Traversing:
Add (expr)
Add (HTML)
Add (elements)
Children (expr)
Contains (STR)
End ()
Filter (expression)
Filter)
Find (expr)
Is (expr)
Next (expr)
Not (EL)
Not (expr)
Not (elems)
Parent (expr)
Parents (expr)
Prev (expr)
Siblings (expr)

Core:
$ (HTML). appendto ("body") is equivalent to writing an htmlCode
$ (Elems) gets an element in the DOM
$ (Function (){........}); Execute a function
$ ("Div> P" ).css ("border", "1px solid gray"); find the subnode P of all Div, add style
$ ("Input: Radio", document. Forms [0]) Search for all radio buttons in the first form on the current page
$. Extend (PROP) prop is a jquery object,
Example:
Jquery. Extend ({
Min: function (a, B) {return a <B? A: B ;},
MAX: function (a, B) {return A> B? A: B ;}
});
Jquery (expression, [Context])-$ (expression, [Context]); by default, $ () queries the DOM elements in the current HTML document.

Each (callback) executes a function using each matching element as the context.
Example: 1
$ ("Span"). Click (function ){
$ ("Li"). Each (function (){
$ (This). toggleclass ("example ");
});
});
Example: 2
$ ("Button"). Click (function (){
$ ("Div"). Each (function (index, domele ){
// Domele = This
((Domele).css ("backgroundcolor", "yellow ");
If ($ (this). Is ("# Stop ")){
$ ("Span"). Text ("stopped at Div index #" + index );
Return false;
}
});
});

Jquery event:

Ready (FN); $ (document). Ready () Note that there is no onload event in the body; otherwise, this function cannot be executed. You can
Many functions are loaded and executed in the FN order.
BIND (type, [data], FN) binds one or more event processor functions for a specific event that matches an element, such as click. Possible event attributes include: blur, focus, load, resize, scroll, unload, click, dblclick, mousedown, mouseup, mousemove,
Mouseover, mouseout, mouseenter, mouseleave, change, select, submit, keydown, keypress,
Keyup, error
One (type, [data], FN) binds one or more event processor functions for a specific event that matches an element, such as click. In each pair
As shown in the preceding figure, the event processing function is executed only once. Other rules are the same as those of the BIND () function.

Trigger (type, [data]) triggers an event on each matching element.
Triggerhandler (type, [data]) triggers a specific event on an element (specify an event type), and cancels the default action of the browser on this event.
Unbind ([type], [data]) is unbound from each matching element.
$ ("P"). Unbind () Remove all bound events in all paragraphs
$ ("P"). Unbind ("click") Remove the Click Event on all paragraphs
Hover (over, out) Over and out are all methods. When you move the cursor over a matching element, the specified first function is triggered. When you move the cursor out of this element, the specified second function is triggered.
$ ("P"). Hover (function (){
$ (This). addclass ("over ");
},
Function (){
$ (This). addclass ("out ");
}
);

toggle (FN, FN) triggers the specified first function if a matching element is clicked. When you click the same element again, the specified second function is triggered.
$ ("p "). toggle (function () {
$ (this ). addclass ("selected");
},
function () {
$ (this ). removeclass ("selected");
}< br>);

Element event list description
Note: For a function without parameters, the parameter is optional fn. Jquery does not support reset events of form elements.
Event Description supports elements or objects.
Blur () element loses focus a, input, textarea, button, select, label, MAP, Area
Change () user changes the field content input, textarea, select
Click () the mouse clicks almost all elements of an object.
Dblclick () double-click almost all elements of an object
Error () an error occurs when a document or image is loaded. Window, IMG
The focus () element obtains the focus a, input, textarea, button, select, label, map, and area.
Keydown () A keyboard key is pressed by almost all elements
Keypress () A keyboard key is pressed or pressed to almost all elements
Keyup () A keyboard key is released to almost all elements
Load (FN) a page or image is loaded. Window, IMG
Mousedown (FN) a mouse button is pressed by almost all elements
Mousemove (FN) the mouse is moved to almost all elements
Mouseout (FN) move the mouse over an element to remove almost all elements.
Mouseover (FN) move the mouse over a certain element to almost all elements
Mouseup (FN) a mouse button is released to almost all elements
Resize (FN) window or frame size adjusted window, IFRAME, Frame
Window when scroll (FN) is rolling the visible part of the document
Select () text selected document, input, textarea
The submit () submit button is clicked by Form
Unload (FN) User exit page window

Jquery Ajax method description:

Load (URL, [data], [callback]) loads a remote HTML content to a DOM node.
$ ("# Feeds"). Load ("feeds.html"); load the feeds.html file into the DIV with the ID of feeds
$ ("# Feeds"). Load ("feeds. php", {limit: 25}, function (){
Alert ("the last 25 entries in the feed have been loaded ");
});

Jquery. Get (URL, [data], [callback]) uses get to request a page.
$. Get ("test. cgi", {name: "John", time: "2"}, function (data ){
Alert ("data loaded:" + data );
});

Jquery. getjson (URL, [data], [callback]) uses get to request JSON data.
$. Getjson ("test. js", {name: "John", time: "2"}, function (JSON ){
Alert ("JSON data:" + JSON. Users [3]. Name );
});

Jquery. getscript (URL, [callback]) uses get to request and execute JavaScript files.
$. Getscript ("test. js", function (){
Alert ("script loaded and executed .");
});
Jquery. Post (URL, [data], [callback], [type]) uses post to request a page.

Ajaxcomplete (callback) executes a function after an Ajax request is completed. This is an Ajax event
$ ("# MSG"). ajaxcomplete (function (request, settings ){
$ (This). append ("<li> request complete. </LI> ");
});
Ajaxerror (callback) executes a function when an Ajax request fails. This is an Ajax event
$ ("# MSG"). ajaxerror (function (request, settings ){
$ (This). append ("<li> error requesting page" + settings. url + "</LI> ");
});

Ajaxsend (callback) executes a function when an Ajax request is sent. This is an Ajax event
$ ("# MSG"). ajaxsend (function (EVT, request, settings ){
$ (This). append ("<LI <starting request at" + settings. url
+ "</LI <");
});

Ajaxstart (callback) executes a function when an Ajax request starts but is not activated. This is an Ajax event
The loading information is displayed when the Ajax request starts (and is not activated ).
$ ("# Loading"). ajaxstart (function (){
$ (This). Show ();
});

Ajaxstop (callback) executes a function when all Ajax operations are stopped. This is an Ajax event
When all Ajax requests are stopped, the loading information is hidden.
$ ("# Loading"). ajaxstop (function (){
$ (This). Hide ();
});

Ajaxsuccess (callback) executes a function after an Ajax request is successfully completed. This is an Ajax event
When the Ajax request is successfully completed, the information is displayed.
$ ("# MSG"). ajaxsuccess (function (EVT, request, settings ){
$ (This). append ("<li> Successful request! </LI> ");
});

Jquery. ajaxsetup (options) sets global settings for all Ajax requests. View the $. Ajax function to obtain all the options.
Set the default global Ajax request option.
$. Ajaxsetup ({
URL: "/XMLHTTP /",
Global: false,
Type: "Post"
});
$. Ajax ({data: mydata });

Serialize () connects a group of input elements by name and value. The correct form element sequence is implemented.
Function showvalues (){
VaR STR = $ ("form"). serialize ();
$ ("# Results"). Text (STR );
}
$ (": Checkbox,: Radio"). Click (showvalues );
$ ("Select"). Change (showvalues );
Showvalues ();

Serializearray () connects all form and form elements (similar to the. serialize () method), but returns a JSON data format.
Obtain a set of values from the form and display them.
Function showvalues (){
VaR fields = $ (": Input"). serializearray ();
Alert (fields );
$ ("# Results"). Empty ();
Jquery. Each (fields, function (I, field ){
$ ("# Results"). append (field. Value + "");
});
}
$ (": Checkbox,: Radio"). Click (showvalues );
$ ("Select"). Change (showvalues );
Showvalues ();

Jquery effects method description

Show () shows hidden matching elements.
Show (speed, [callback]) displays all matching elements in an elegant animation, and triggers a callback function optional after the display is complete.
Hide () hides all matching elements.
Hide (speed, [callback]) hides all matching elements with elegant animations, and triggers a callback function after the display is complete.
Toggle () switches the visible state of the element. If the element is visible, switch to hidden. If the element is hidden,
Switch to visible.
Slidedown (speed, [callback]) dynamically displays all matching elements by changing the height (increasing down). Optional
To trigger a callback function. This animation only adjusts the height of the element, so that the matching element can be
The "slide" mode is displayed.
Slideup (speed, [callback]) dynamically hides all matching elements by changing the height (decreasing upwards). It is optional after hiding.
Triggers a callback function. This animation only adjusts the height of the element, so that the matching element can be "slide"
.
Slidetoggle (speed, [callback]) switches the visibility of all matching elements through height changes, and triggers an optional response after switching.
Call a function. This animation only adjusts the height of the element, so that the matching element is hidden in a "slide" way.
Hidden or displayed.
Fadein (speed, [callback]) realizes the fade-in effect of all matching elements by changing the opacity. After the animation is complete, it can be triggered.
Send a callback function. This animation only adjusts the opacity of the element, that is,
The height and width do not change.
Fadeout (speed, [callback]) fades out all matching elements by changing the opacity. After the animation is complete
Send a callback function. This animation only adjusts the opacity of the element, that is,
The height and width do not change.
Fadeto (speed, opacity, [callback]) Incrementally adjusts the opacity of all matching elements to the specified opacity and completes the animation.
Then, a callback function is triggered. This animation only adjusts the opacity of the element, that is,
The height and width of a matched element do not change.
Stop () stops all animations that match the element that are currently running. If an animation is in the queue, it starts immediately.
Queue () gets the reference of the first animation sequence that matches the element (returns an array whose content is a function)
Queue (callback) adds an executable function at the end of the event sequence of each matching element as the event function of this element.
Queue (Queue) replaces the original animation sequence of all matching elements with a new animated sequence
Dequeue () executes and removes the animation at the front end of the animation sequence
Animate (Params, [duration], [easing], [callback]) is a function used to create a custom animation.
Animate (Params, options) is another way to create a custom animation. Same as above.

Jquery traversing method description

Eq (INDEX) obtains an element at the specified position from the matched element set, and the index starts from 0.
Filter (expr) returns a set of elements that match the specified expression. You can use the "," sign to separate multiple expr for filtering by multiple conditions.
Filter (FN) uses a special function as a filter condition to remove unmatched elements from the set.
Is (expr) uses an expression to check the selected element set. If at least one element matches the given
Returns true for the expression.
Map (callback) converts a group of elements in the jquery object using the callback method, and then adds them to a jquery array.
Not (expr) removes the elements that match the specified expression from the matched element set.
Slice (START, [end]) obtains a subset from the Matching Element Set, which is the same as the Slice Method of the built-in array.
Add (expr) adds the elements matching the expression to the jquery object.
Children ([expr]) obtains a set of elements that contain all child elements of each element in a matched element set. Optional Filters
This method will match only the Conforming Elements (including only the element node, not the text node ).
CONTENTS () obtains a set of all child nodes of each element in a matched element set (only including element nodes, not
Including text nodes). If the element is IFRAME, the document element is obtained.
Find (expr) searches for all elements that match the specified expression.
Next ([expr]) gets a set of elements next to each element in the matched element set.
Nextall ([expr]) obtains a set of elements that contain all the following peer elements of each element in the matched element set.
Parent ([expr]) obtains a set of elements that contain the unique parent element of all matching elements.
Parents ([expr]) obtains a set of elements (excluding the root element) that contain the unique ancestor element of all matching elements ).
Prev ([expr]) obtains a set of elements that match the previous generation element next to each element in the element set.
Prevall ([expr]) obtains a set of elements that contain all the previous peer elements of each element in the matched element set.
Siblings ([expr]) obtains an element set of all peer elements of each element in a matched element set.
Andself () adds the previous Matching Element Set to the current set
Obtain all DIV elements and P elements, and add border class attributes. Obtain the P element of all DIV elements,
Add background class attributes
$ ("Div"). Find ("p"). andself (). addclass ("border ");
$ ("Div"). Find ("p"). addclass ("background ");
End () ends the current operation and returns to the previous operation of the current operation.
Locate the span element set in all P elements, return the P element set, and add the CSS attribute.
$ ("P"). Find ("span" cmd.end(cmd.css ("border", "2px red solid ");

Jquery selectors method description

Basic Selector
$ ("# Mydiv") matches a unique element with this ID value
$ ("Div") matches all elements of the specified name
$ (". Myclass") matches all elements with this class style Value
$ ("*") Matches all elements
$ ("Div, span, P. myclass") associates with all matching selectors
Cascade Selector
$ ("Form input") descendant selector, select all descendant nodes of ancestor
$ ("# Main> *") Child selector, select all child nodes of the parent
$ ("Label + input") Select the next node of Prev
$ ("# Prev ~ Div ") compatriot selector, select all compatriot nodes of Prev
Basic filter Selector
$ ("TR: First") matches the first selected Element
$ ("TR: Last") matches the last selected Element
$ ("Input: Not (: checked) + span") filter out all elements matching the selector from the original element set (here there is a temporary selector)
$ ("TR: Even") matches all elements in the even position of the Set (starting from 0)
$ ("TR: odd") matches all elements at the odd position in the Set (starting from 0)
$ ("TD: eq (2)") matches the elements at the specified position in the Set (starting from 0)
$ ("TD: GT (4)") matches all elements after a specified position in the Set (starting from 0)
$ ("TD: Gl (4)") matches all elements before the specified position in the Set (starting from 0)
$ (": Header") matches all titles
$ ("Div: animated") matches all elements of all running animations
Content Filter Selector
$ ("Div: Contains ('john')") matches all elements containing the specified text
$ ("TD: empty") matches all empty elements (elements containing only text are not empty)
$ ("Div: Has (p)") matches all elements containing at least one selector from the original element set again
$ ("TD: parent") matches all non-null elements (elements containing text are also considered)
$ ("Div: hidden") matches all hidden elements, including the hidden fields of the form.
$ ("Div: visible") matches all visible elements
Attribute filter Selector
$ ("Div [ID]") matches all elements with specified attributes
$ ("Input [name = 'newsletter ']") matches all elements with specified attribute values.
$ ("Input [name! = 'Newsletter'] ") matches all elements that do not have the specified attribute value.
$ ("Input [name ^ = 'News']") matches all elements whose specified attribute values start with value.
$ ("Input [name $ = 'Letter ']") matches all elements whose values end with values.
$ ("Input [name * = 'man']") matches all elements whose specified property value contains the value character.
$ ("Input [ID] [name $ = 'man']") matches all elements that match multiple selectors at the same time.
Child element filter Selector
$ ("Ul Li: Nth-child (2 )"),
$ ("Ul Li: Nth-child (ODD)") matches the nth child element of the parent element.
$ ("Ul Li: Nth-child (3N + 1 )")

$ ("Div span: First-Child") matches the 1st child element of the parent Element
$ ("Div span: Last-Child") matches the last child element of the parent Element
$ ("Div button: Only-Child") matches the unique child element of the parent element.
Form element Selector
$ (": Input") matches all form input elements, including all types of input, textarea, select, And button
$ (": Text") matches all input elements of the text type.
$ (": Password") matches all input elements of the password type.
$ (": Radio") matches all input elements of the radio type.
$ (": Checkbox") matches all input elements whose types are checkbox.
$ (": Submit") matches all input elements of the submit type.
$ (": Image") matches all input elements of the image type.
$ (": Reset") matches all input elements of the reset type.
$ (": Button") matches all input elements of the button type.
$ (": File") matches all input elements whose types are file.
$ (": Hidden") matches the hidden fields of all input elements or forms of the hidden type.
Form element filter Selector
$ (": Enabled") matches all operable form elements
$ (": Disabled") matches all form elements that cannot be operated
$ (": Checked") matches all selected elements
$ ("Select option: Selected") matches all selected elements

Jquery CSS

CSS (name) accesses the style attribute of the First Matching Element.
CSS (properties) sets a "name/value pair" object as the style attribute of all matching elements.
$ ("p "). hover (function () {
Functions (this).css ({backgroundcolor: "yellow", fontweight: "Bolder"});
}, function () {
var cssobj = {
backgroundcolor: "# DDD",
fontweight: "",
color: "#0028f4"
}< br> exist (thisbj .css (cssobj);
});
CSS (name, value) among all matched elements, set the value of a style attribute.
offset () gets the position of the First Matching Element relative to the current visible window. The returned object has two attributes:
top and left. The attribute value is an integer. This function can only be used for visible elements.
var P = $ ("P: Last");
var offset = P. offset ();
p.html ("Left:" + offset. left + ", top:" + offset. top);
width () gets the width value of the First Matching Element.
width (VAL) sets the specified width value for each matching element.
height () gets the height value of the First Matching Element.
height (VAL) sets the specified height value for each matching element.

Jquery utilities method description
Jquery. Browser
. MSIE indicates IE
Jquery. browser. version reads the version information of the user's browser.
Jquery. boxmodel: checks whether the browser displays the current page based on the W3C CSS box model.
Jquery. isfunction (OBJ) checks whether the passed parameter is a function
Function stub (){}
VaR objs = [
Function (){},
{X: 15, Y: 20 },
Null,
Stub,
"Function"
];
Jquery. Each (objs, function (I ){
VaR isfunc = jquery. isfunction (objs [I]);
$ ("Span: eq (" + I + ")"). Text (isfunc );
});
Jquery. Trim (STR) clears spaces at both ends of a string and uses regular expressions to clear spaces at both ends of a given character
Jquery. Each (object, callback) is a common iterator that can be used to seamlessly iterate objects and arrays.
Jquery. Extend (target, object1, [objectn]) extends an object, modifies the original object, and returns it. This is a powerful implementation inherited
Tool, this inheritance is implemented by passing values, rather than in Javascript
Original Type Chain Mode.
Merge settings and options objects, and return the modified settings object.
VaR settings = {validate: false, limit: 5, name: "foo "};
VaR Options = {validate: True, name: "bar "};
Jquery. Extend (settings, options );

Merge the ults and options objects. The defaults object is not modified. Options object Value
The value of the ults object is passed to empty.

var empty ={}< br> var defaults = {validate: false, limit: 5, name: "foo" };
var Options = {validate: true, name: "bar" };< br> var settings = $. extend (empty, defaults, options);
jquery. grep (array, callback, [invert]) removes items in the array using a filter function
$. grep ([0, 1, 2], function (n, I) {
return n> 0;
});
jquery. makearray (OBJ) converts an object similar to an array into a real array
converts the selected Div element set to an array
var arr = jquery. makearray (document. getelementsbytagname ("Div");
arr. reverse (); // use an array method on List of DOM elements
$ (ARR ). appendto (document. body);
jquery. map (array, callback) uses a method to modify the items in an array, and then returns a new array
jquery. inarray (value, array) returns the position of value in the array. If no value is found,-1 is returned.
jquery. unique (array) deletes all repeated elements in the array and returns the sorted array.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.