jqueryhtml() method


  Translation results:

HTML

English [ˌeɪtʃ ti: em ˈel] US [ˌetʃtiɛmˈɛl]

abbr.Hypertext Markup Language Hypertext Markup Language

jqueryhtml() methodsyntax

Function: html() method returns or sets the content of the selected element (inner HTML). If this method does not set parameters, it returns the current content of the selected element.

Return element content: When using this method to return a value, it will return the content of the first matching element.

Syntax: $(selector).html()

Set element content: When this method is used to set a value, it will be overwritten The contents of all matching elements.

Syntax: $(selector).html(content)

Parameters:

ParameterDescription
content Optional. Specifies the new content of the selected element. This parameter can contain HTML tags.

#Use functions to set the content of elements: Use functions to set the contents of all matching elements.

Syntax: $(selector).html(function(index,oldcontent))

Parameters:

ParametersDescription
function(index,oldcontent) Specifies a new value that returns the selected element Content function.
index Optional. Receives the index position of the selector.
oldcontent Optional. Receives the current contents of the selector.

jqueryhtml() methodexample

<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js></script>
<script type="text/javascript">
$(document).ready(function(){
  $(".btn1").click(function(){
    $("p").html("Hello <b>world!</b>");
  });
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button class="btn1">改变 p 元素的内容</button>
</body>
</html>
Run instance »

Click the "Run instance" button to view the online instance

Popular Recommendations

Home

Videos

Q&A