W3school---JQuery HTML

Source: Internet
Author: User

DOM = Document Object model

Three simple and practical jQuery methods for DOM manipulation:

    • Text ()-Sets or returns the text content of the selected element
    • HTML ()-Sets or returns the contents of the selected element (including HTML tags)
    • Val ()-Sets or returns the value of a form field
Gets the Property-attr (): $ ("#w3s"). attr ("href"); Set property value: $ ("#w3s"). attr ("href", "http://www.w3school.com.cn/jquery"); Use Object ({" href ":" www "," title ":" http "}) can be set multiple at the same time.
The callback function for text (), HTML (), and Val ():The callback function consists of two parameters: the subscript I of the current element in the selected element list, and the original (old) value Origvalue.
$ ("button"). Click (function () {$ ("#w3s"). attr ("href", function (i,origvalue) {   return origvalue + "/jquery";});  });
Add a new HTML content
    • Append ()-Inserts the content at the end of the selected element, in the element
    • Prepend ()-Inserts the content at the beginning of the selected element, in the element
    • After ()-Inserts the content after the selected element,
    • Before ()-insert content before selected element
Delete element/content

The JQuery Remove () method deletes the selected element and its child elements.

The JQuery Empty () method deletes the child elements of the selected element.

The JQuery Remove () method can also accept a parameter that allows you to filter the deleted element. That is, only those with parameters are deleted.

JQuery operation CSS (CSS parameters)
    • AddClass ()-adds one or more classes to the selected element
    • Removeclass ()-deletes one or more classes from the selected element
    • Toggleclass ()-switch operation to add/Remove classes for selected elements
    • CSS ()-Sets or returns the style properties. Returns ( first ) The value of the specified CSS property, setting the style css ({"PropertyName": "Value", "PropertyName": "Value",...});

Width/Height:

  • Width (),height (): Gets the $ (document). width ();   $ (window). width (); Set:$ ("#div1"). Width (+). Height (+);
  • Innerwidth (),innerheight () returns the width height of the element (including padding)
  • Outerwidth (),outerheight () returns the width and height of the element ( including padding and borders )

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.