JQuery-Set content and property settings Content-text (), HTML (), and Val (), Set properties-attr ()

Source: Internet
Author: User

JQuery-Set content and property settings 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

The following example shows how to set the content by using the text (), HTML (), and Val () methods:

Instance
$ ("#btn1"). Click (function () {  $ ("#test1"). Text ("Hello world!");}); $ ("#btn2"). Click (function () {  $ ("#test2"). HTML ("<b>hello world!</b>");}); $ ("#btn3"). Click (function () {  $ ("#test3"). Val ("Dolly Duck");});


The JQuery attr () method is also used to set/change property values.

The attr () method also allows you to set multiple properties at the same time.

The following example shows how to set the href and title properties at the same time:

Instance
$ ("button"). Click (function () {  $ ("#w3s"). attr ({    "href": "Http://www.w3school.com.cn/jquery",    "title" : "W3school jQuery Tutorial"  });

JQuery-Set content and property settings Content-text (), HTML (), and Val (), Set properties-attr ()

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.