Getting Started with jquery (a) HTML get

Source: Internet
Author: User
Tags jquery library

The jquery library contains a number of ways to change and manipulate HTML elements and their attributes.

One very important part of this is that jquery can be used to manipulate the DOM.

This article describes using jquery to get the values or attributes of a DOM node element.

One of the three simple and useful methods are as follows:

Text () – Sets or gets the textual content of the specified element.

HTML () – Sets or gets the contents of the specified element (including HTML markup)

Val () – Sets or gets the value of an input field for the form.

For example, the following code uses the HTML () and text () methods to get the contents of an HTML element:

$ ("#btn1"). Click (function () {     
  alert ("Text:" + $ ("#test"). Text ();     
});     
$ ("#btn2"). Click (function () {     
  alert ("HTML:" + $ ("#test"). html ();     
});

The following code gets the contents of the input in form:

$ ("#btn1"). Click (function () {     
  alert ("Value:" + $ ("#test"). Val ());     

In addition to the above method, the attr () method is used to obtain the attributes of an element:

The following code is used to get the href attribute of the link:

<! DOCTYPE html>     

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.