jquery Self-study Note (iv): JQuery DOM node operation

Source: Internet
Author: User

Get and set content: Text (), HTML (), and Val ()
    • 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
Example: $ ("#btn1"). Click (function () {
$ ("#test1"). Text ("Hello world!");
});
$ ("#btn2"). Click (function () {
$ ("#test2"). HTML ("<b>hello world!</b>");
});
$ ("#btn3"). Click (function () {
$ ("#test3"). Val ("Dolly Duck");
}); To set and modify properties:The attr () method is used to set the Change property value. Example: $ ("button"). Click (function () {
$ ("#w3s"). attr ({
"href": "Http://www.w3school.com.cn/jquery",
"title": "W3school jQuery Tutorial"
});}); to add new HTML content:
    • Append ()-inserts content at the end of the selected element
    • Prepend ()-Inserts content at the beginning of the selected element
    • After ()-Inserts the content after the selected element
    • Before ()-insert content before selected element
Delete element/content:
    • Remove ()-Deletes the selected element (and its child elements)
    • Empty ()-Removes child elements from the selected element
jQuery operation CSS:
    • AddClass ()-adds one or more classes to the selected element, and, of course, when you add a class, you can also select multiple elements
    • Removeclass ()-deletes one or more classes from the selected element
    • Toggleclass ()-switch operation to add/Remove classes for selected elements
    • CSS ()-Set or return style properties
jQuery Toggleclass () method:This method switches the selected element to the Add/remove class, for example: $ ("button"). Click (function () {
$ ("H1,h2,p"). Toggleclass ("Blue");}); To set CSS properties:To set the specified CSS property, use the following syntax (multiple): CSS ({"PropertyName": "Value", "PropertyName": "Value",...}); jQuery Size Method:JQuery offers several important ways to handle dimensions:
    • Width ()
    • Height ()
    • Innerwidth ()
    • Innerheight ()
    • Outerwidth ()
    • Outerheight ()
The width () method sets or returns the width of the element (excluding padding, borders, or margins) of the height () method to set or return the elements ' heights (excluding padding, borders, or margins) innerwidth () method returns the width of the element (including padding) innerheight () method returns the height of the element (including padding) the Outerwidth () method returns the width of the element (including padding and borders) Outerheight () method returns the height of the element (including padding and borders) Outerwidth (True) method returns the width of the element (including padding , borders, and margins) the Outerheight (True) method returns the height of the element (including padding, borders, and margins)

jquery Self-study Note (iv): JQuery DOM node operation

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.