Metoda jQuery replaceWith()

❮ Metody jQuery HTML/CSS

Przykład

Zastąp pierwszy element <p> nowym tekstem:

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

Definicja i użycie

Metoda replaceWith() zastępuje wybrane elementy nową zawartością.


Składnia

$(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

Spróbuj sam - przykłady


Jak używać funkcji do zastępowania wybranych elementów nową zawartością.


❮ Metody jQuery HTML/CSS