Metoda jQuery html() .

❮ jQuery HTML/CSS metody

Příklad

Změňte obsah všech prvků <p>:

$("button").click(function(){
  $("p").html("Hello <b>world</b>!");
});

Definice a použití

Metoda html() nastavuje nebo vrací obsah (innerHTML) vybraných prvků.

Když se tato metoda použije k vrácení obsahu, vrátí obsah PRVNÍHO shodného prvku.

Když je tato metoda použita k nastavení obsahu, přepíše obsah VŠECH odpovídajících prvků.

Tip: Chcete-li nastavit nebo vrátit pouze textový obsah vybraných prvků, použijte metodu text() .


Syntax

Vrátit obsah:

$(selector).html()

Obsah sady:

$(selector).html(content)

Nastavte obsah pomocí funkce:

$(selector).html(function(index,currentcontent))

Parameter Description
content Required. Specifies the new content for the selected elements (can contain HTML tags)
function(index,currentcontent) Optional. Specifies a function that returns the new content for the selected elements
  • index - Returns the index position of the element in the set
  • currentcontent - Returns the current HTML content of the selected element

Zkuste si to sami - příklady


Jak vrátit obsah prvku.


Pomocí funkce nastavíte obsah všech vybraných prvků.


❮ jQuery HTML/CSS metody