Common methods of jquery

Source: Internet
Author: User

About properties

Javascript:

    • GetAttribute
    • SetAttribute
    • RemoveAttribute

Jquery:

    • attr
    • Removeattr
    1. attr (incoming property name): Gets the value of the property
    2. Attr (property name, property value): Sets the value of the property
    3. Attr (property name, function value): Sets the function value of the property
    4. attr (attributes): Sets multiple attribute values for the specified element: {attribute name one: attribute value one, property name two: ' Property value two ', ...}
About content

Javascript:

    • InnerHTML

Jquery:

    • Html
    • Text
    1. . HTML () does not pass in a value, which is the HTML content that gets the first matching element in the collection
    2. . HTML (htmlstring) sets the HTML content of each matching element
    3. . HTML (function (index, oldhtml)) is used to return a function that sets HTML content

The. HTML () method is used internally by the DOM's innerHTML property to handle, so one of the most important issues to be aware of in terms of setup and acquisition is the entire HTML content (not just text content)

    1. . Text () Gets the merged text of each element in the matching element collection, including their descendants
    2. . Text (TextString) used to set the content of matching elements
    3. . text (function (index, text)) is used to return a function that sets the text content

The. Text () result returns a string containing the merged text for all matching elements

    1. The. Html method operation is the same as the. text, except that it is specific to the processing object
    2. . HTML handles the content of elements,. Text handles textual content
    3. . HTML can only be used in HTML documents, and. Text can be used in both XML and HTML documents
    4. If the object you are working with has only one child text node, the result of HTML processing is the same as text.
    5. Firefox does not support the InnerText property, using a similar textcontent property, the. Text () method combines support for 2 properties, so it can be compatible with all browsers
About values

Val () is used primarily for input, select, and textarea

    1. Val () No parameter, gets the current value of the first element in the matching element collection
    2. . val (value), sets the value of each element in the matching element collection
    3. . val (functions), a function to return the set value

Ps:

    1. The select element is processed through. Val (), and when no selection is selected, it returns null
    2. The. Val () method is used to set the value of the form's field
    3. If the select element has a multiple (multiple-selection) attribute, and at least one selection is selected, the. Val () method returns an array that contains the value of each selected selection

Summary of differences between. html (),. Text (), and. Val ():

    1. . HTML (),. Text (),. Val () Three methods are used to read the contents of the selected element; HTML () is used to read the elements of the HTML content (including HTML tags),. Text () is used to read the plain text content of the element, including its descendant elements,. Val () Is the "value" value that is used to read form elements. where the. html () and. Text () methods cannot be used on form elements, whereas. val () can only be used on form elements, and the. html () method only reads the first element when used on more than one element; the. val () method is the same as. html () If it is applied on more than one element. You can only read the value of the first FORM element (but Val can return multiple values if the Select is multi-select), but. Text () is not the same as they are, if. Text () is applied on more than one element, the textual content of all the selected elements is read.
    2. . HTML (htmlstring),. Text (TextString), and. Val (value) Three methods are used to replace the contents of the selected element, and if three methods are applied on more than one element at the same time, the contents of all the selected elements will be replaced.
    3. . HTML (),. Text (),. Val () can use the return value of the callback function to dynamically change the contents of multiple elements.
About class operations

AddClass Add Style

    1. . addclass (ClassName): One or more style names to add for each matching element
    2. . addclass (function (index, currentclass)): This function returns one or more style names to be added separated by spaces

Removeclass Delete a style

    1. . Removeclass ([ClassName]): One or more space-delimited style names removed by each matching element
    2. . Removeclass (Function (Index, Class)): A function that returns one or more style names that will be removed

Toggleclass Toggle Style

    1. . Toggleclass (ClassName): one or more (separated by spaces) style class names that are used to toggle on each element in the matching element collection
    2. . Toggleclass (className, switch): A Boolean value that determines whether a style should be added or removed
    3. . Toggleclass ([switch]): A Boolean value that is used to determine whether a style class is added or removed
    4. . Toggleclass (Function (Index, class, switch) [, switch]): A function that returns the name of the style class used to toggle on each element in the matching element collection. Receives the index position of the element and the element's old style class as a parameter
About Styles

Get:

    1. . CSS (PropertyName): Gets the computed value of the style property of the first element in the matching element collection
    2. . CSS (propertynames): Passing a set of arrays, returning an object result

Set up:

    1. . CSS (propertyname, value): Set CSS
    2. . CSS (propertyname, function): You can pass in a callback function and return to the corresponding value for processing
    3. . CSS (properties): You can pass an object and set multiple styles at the same time
About storage
    • Jquery.data (element, key, value)//static interface, storage data
    • Jquery.data (element, key)//static interface, fetching data
    • . Data (key, value)//instance interface, memory
    • . Data (key)//instance interface, memory

    • Jquery.removedata (element [, name])
    • . Removedata ([name])

Common methods of jquery

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.