Differences between text (), html (), val () in js, and jsval

Source: Internet
Author: User

Differences between text (), html (), val () in js, and jsval

Differences between text (), html (), and val () in js

 

The text (), html (), and val () methods are used to store values and values of html elements, but they have their own characteristics. text () is used to access html element text content, html () can be used not only to access html element text content, but also to access html content. Val () is used to access the content of input elements.

I. text ()

Var text = $ ("div"). text ();

Console. log (text );

<Div> text </div>

Console: text

  

Ii. html ()

<Div> <p> text </p> </div>

Var str = $ ("div" pai.html ();

Console. log (str );

Console: <p> text </p>

Iii. val ()

<Input type = "text" value = "text"/>

Var str = $ ("input"). val ();

Console. log (str );

Console: text

Similarities and Differences:

Both text () and html () can be used for element text access, but html () can be used for element text access and Element Node access.

Unlike text () and html (), val () is used to access the content of input nodes.

 

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.