JQuery-Get content and properties

Source: Internet
Author: User

1. Get content: Text (), HTML (), Val ()

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

2. Get Properties: ATRR ()

The JQuery attr () method is used to get the property value.

1) Get the <a> href

$ ("a"). attr ("href")

2) obtained from the defined attribute

<p zhen= "true" > Total </p>

$ ("P"). attr ("Zhen")

Note: The above is the value that returns the selected element, as well as the setting property and value.

1) Set the attributes and values of the selected element.

Syntax: $ (selector). attr (attribute,value)

Usage: $ ("img"). attr ("width", "180"); //Get the width of the image

2) Use the function to set the attribute/value of the selected element

Syntax: $ (selector). attr (attribute,function (index,oldvalue))

Usage: $ ("img"). attr ("width", function (n,v) {

return v-50;

               }); //Reduce the width of the image by 50 pixels

3) set more than one attribute and value for the selected element.

Syntax: $ (selector). attr ({attribute:value, attribute:value ...})

Usage: $ ("img"). attr ({width: "", "Height:"}); Set the width and height of the image

JQuery-Get content and properties

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.