Metoda jQuery replaceWith().

❮ jQuery HTML/CSS metody

Příklad

Nahraďte první prvek <p> novým textem:

$("button").click(function(){
   $("p:first").replaceWith("Hello world!");
});

Definice a použití

Metoda replaceWith() nahradí vybrané prvky novým obsahem.


Syntax

$(selector).replaceWith(content,function(index))

Parameter Description
content Required. Specifies the content to insert (can contain HTML tags)

Possible values:

  • HTML elements
  • jQuery objects
  • DOM elements
function(index) Optional. Specifies a function that returns the content to replace
  • index - Returns the index position of the element in the set

Zkuste si to sami - příklady


Jak používat funkci k nahrazení vybraných prvků novým obsahem.


❮ jQuery HTML/CSS metody