jQuery метод replaceWith()

❮ Методы jQuery HTML/CSS

Пример

Замените первый элемент <p> новым текстом:

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

Определение и использование

Метод replaceWith() заменяет выбранные элементы новым содержимым.


Синтаксис

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

Попробуйте сами - примеры


Как использовать функцию для замены выбранных элементов новым содержимым.


❮ Методы jQuery HTML/CSS