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 메소드