Home >Web Front-end >JS Tutorial >jquery learning part 2 attributes (html() and html(val))_jquery

jquery learning part 2 attributes (html() and html(val))_jquery

WBOY
WBOYOriginal
2016-05-16 18:15:321095browse
html()
Get the html content of the first matching element. This function cannot be used with XML documents. But it can be used for XHTML documents.
Get the html contents of the first matched element. This property is not available on XML documents (although it will work for XHTML documents).
Return value
String

Example
Copy code The code is as follows:

HTML code:

< p>Hello


jQuery code:

$("div").html();

Result:

Hello

html(val)
Set the html content of each matching element. This function cannot be used with XML documents. But it can be used for XHTML documents.
Set the html contents of every matched element. This property is not available on XML documents (although it will work for XHTML documents).
Return value
jQuery

Parameters
val (String): Value used to set HTML content

Example
Copy code The code is as follows:

HTML code:

jQuery code:
$("div").html("

Hello Again


Result:
[

Hello Again

]
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn