JQuery-Get content and properties

Source: Internet
Author: User

JQuery has a powerful way to manipulate HTML elements and attributes.

JQuery DOM Operations

A very important part of JQuery is the ability to manipulate the DOM.

JQuery provides a series of DOM-related methods that make it easy to access and manipulate elements and attributes.

DOM = Document Object model

The DOM defines the criteria for accessing HTML and XML documents:

The Document Object model is platform-and language-independent, allowing programs and scripts to dynamically access and update the content, structure, and style of the document. "

Get Content-text (), HTML (), and 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

The following example shows how to get the content using the JQuery text () and HTML () methods:

Instance $ ("#btn1"). Click (function () {
Alert ("Text:" + $ ("#test"). Text ());
});
$ ("#btn2"). Click (function () {
Alert ("HTML:" + $ ("#test"). html ());
});
Try it»

The following example shows how to get the value of an input field using the JQuery Val () method:

Instance $ ("#btn1"). Click (function () {
Alert ("Value:" + $ ("#test"). Val ());
});
Try it»

Get Property-attr ()

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

The following example shows how to get the value of the href attribute in the link:

Instance $ ("button"). Click (function () {
Alert ($ ("#w3s"). attr ("href"));
});
Try it»

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.