html([val|fn])

html([val|fn])

Outline

Get the first match html content elements. This function can not be used in XML documents. But it can be used for XHTML documents. Linear motor selection

In an HTML document, we can use the .html () method to get an arbitrary element content. If you choose to match more than one element, then only the first matching element in HTML content will be acquired.

parameter

val String V1.0

Value is set for HTML content

function(index, html)FunctionV1.4

This function returns an HTML string. It accepts two parameters, index for the elements in a set position index, html for the original HTML value.

Examples

No Parameter Description:

Returns the contents of p elements.

jQuery code:
$('p').html();

Parameter Description val:

The contents of all elements of the set p

jQuery code:
$("p").html("Hello <b>world</b>!");

The callback function Description:

Use function to set all the content matched elements.

jQuery code:
$("p").html(function(n){
    return "这个 p 元素的 index 是:" + n;
    });

Guess you like

Origin www.cnblogs.com/furuihua/p/12002340.html