A common method of jquery's manipulation of DOM

Source: Internet
Author: User

JQuery's operations on the DOM are also very important.

1. Three simple and practical jQuery methods for DOM operations:

text ()-Sets or returns the text content of the selected element

HTML ()-Sets or returns the selected Element (including HTML markup)

val ()-Sets or returns the value of the form field

2.attr () Get Properties . Of course, these two can also set their own values to modify,

3. Add to HTML content . Add new HTML Content

We'll learn four jQuery methods for adding new content:

append ()-inserting content at the end of the selected element

prepend ()-inserting content at the beginning of the selected element

after ()-Inserts the content after the selected element

before ()-Inserts the content before the selected element

4. Delete element/content

If you want to delete meta Elements and content, you can generally use the following two JQuery methods:

Remove ()-Delete selected elements (and their children)

Empty ()-Remove child elements from selected elements

5.jQuer The Y action css

JQuery has several methods for CSS manipulation. We will study the following:

addclass ()-add one or more classes to the selected element

removeclass ()-Remove one or more classes from the selected element

toggleclass ()-pairs of selected elements Switch operations for Add/Remove classes

css ()-Set or Return style properties

Example

$ ("H1,h2,p"). AddClass ("Blue"); first we know when When adding styles to multiple tags, we use ', ' to separate them. Blue must be a set. blue{} class SelectionSelector

$ ("H1,h2,p"). Removeclass ("Blue");

$ ("H1,h2,p"). Toggleclass ("Blue"); a style is removed, and no style adds

6. Set multiple CSS Properties

If you want to set up multiple CSS genera , use the following syntax:

CSS ({"PropertyName": "Value", "PropertyName": "Value",...}); The

7.jQuery Dimension method

Jquerywidth () and Height () methods

Width () method sets or returns the width of the element (excluding the inner margin, border, or outside) Distance). The

Height () method sets or returns the height of the element (excluding the inner margin, border, or outer margin). The

Jqueryinnerwidth () and Innerheight () methods

Innerwidth () methods return the width of the element, including the inner margin. The

Innerheight () method returns the height of the element, including the inner margin. The

Jqueryouterwidth () and Outerheight () methods

Outerwidth () methods return the width of the element, including the inner margin and border. The

Outerheight () method returns the height of the element, including the inner margin and border.

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.