JQuery getting started tutorial (12): HTML Get

Source: Internet
Author: User

The jQuery library contains many methods for changing and operating HTML elements and their attributes. One of the most important parts is that jQuery can be used to operate the DOM. This article describes how to use jQuery to obtain the values or attributes of DOM node elements. Three simple and useful methods are as follows: text ()-set or retrieve the text content of a specified element. Html ()-set or retrieve the content of a specified Element (including HTML tags) val ()-set or retrieve the value of an input field in the form. For example, the following code uses the html () and text () methods to obtain the content of HTML elements: [javascript] $ ("# btn1 "). click (function () {alert ("Text:" + $ ("# test "). text () ;}); $ ("# btn2 "). click (function () {alert ("HTML:" + $ ("# test" example .html () ;}); $ ("# btn1 "). click (function () {alert ("Text:" + $ ("# test "). text () ;}); $ ("# btn2 "). click (function () {alert ("HTML:" + $ ("# test" ).html () ;}); the following code retrieves the Input content in Form: [javascript] $ ("# btn1 "). click (function () {alert ("Va Lue: "+ $ (" # test "). val () ;}); $ ("# btn1 "). click (function () {alert ("Value:" + $ ("# test "). val () ;}); apart from the preceding method, the attr () method is used to obtain the attributes of an element. The following code is used to obtain the href attribute of the link: [html] <! DOCTYPE html>

Related Article

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.