jquery learning------HTML () and text ()

Source: Internet
Author: User

jquery learning------HTML () and text ()

The similarities and differences between HTML and. Text:

    1. The. Html method operation is the same as the. text, except that it is specific to the processing object
    2. . HTML handles the content of elements,. Text handles textual content
    3. . HTML can only be used in HTML documents, and. Text can be used in both XML and HTML documents
    4. If the object you are working with has only one child text node, the result of HTML processing is the same as text.
    5. Firefox does not support the InnerText property, using a similar textcontent property, the. Text () method combines support for 2 properties, so it can be compatible with all browsers

Example:

<div class= "Soulsjie" >
</div>

<p></p>
<p></p>

<script type= "Text/javascript" >
Show what the HTML method gets
. HTML () is the entire HTML document structure
$ (' P:first '). Text ($ (". Soulsjie"). HTML ())

Shows what the text method gets
. Text () is a collection of textual content
$ (' p:last '). Text ($ (". Soulsjie"). Text ())
</script>

Output Result:

Simply speaking, use. html () to get tags and content to HTML, and use. Text () to get only the contents of the label

Get the original content, modify it, and re-assign it through the callback of the. Text ()

<script type= "Text/javascript" >
$ (". Left A:first"). Text (function (idnex,text) {

Index is the meaning of the indexed value, the index is $ ('. Left A:first '), and the other argument text is an existing text content in $ ('. Left A:first ')
Return ' Add new text content ' + text
})
</script>




jquery learning------HTML () and text ()

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.