text () and html () difference

Two days looked html and jquery selectors, online editing and w3chool above an interest, but an error occurs in the show background with pure html textarea time, access to a variety of information found not ...... mind explode. Ado, on dry goods.

First, html property has two methods, a parameter, a parameter-free.

  1. No reference html (): get the first match html content elements. This function can not be used in XML documents. But can be used for XHTML documents, it returns a String
    example:

html page code:

Hello there

jquery Code: $ ( "div") html ();.

Results: Hello (acquisition sub-labels and text content)
2. html parameters (Val): html content provided for each matching element. This function can not be used in XML documents. But it can be used for XHTML documents. Jquery object returns an
html page code:

jquery Code: $ ( "div") html ( ".

I love you China

”);

The browser displays the result is: I love you, China (that is to say the browser can recognize we insert into the tag)

Secondly, text attribute has two methods, a parameter, a parameter-free

  1. No reference text (): access to all content matching elements. The result is a combination of all of the text element contains a matching up text. It returns a String.

example:

html page code:

Hello there

well

jquery Code: $ ( "p") text ();.

Results: Hello good (only selected text below the label, the label can not be identified identified)
 

2. Reference text (val): set all text matching elements, similar to HTML (), but HTML coding (the "<" and ">" with the corresponding HTML entities) Returns a jquery object.

html page code:

Paragraph.

jquery Code: $ ( "div") text ( ". Haha, I would be a complete output new text.");

result:

Haha, I would be a complete output new text.

(Html ​​tags will not be recognized browser, but as a string output)

Author: Jonckys
Source: CSDN
Original: https://blog.csdn.net/qq_20617983/article/details/81105617
Copyright: This article is a blogger original article, reproduced, please attach Bowen link!

Guess you like

Origin www.cnblogs.com/luowenConnor/p/11247512.html