English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
replaceWith() 메서드는 선택된 요소를 새로운 내용으로 대체합니다.
replaceWith() 메서드는replaceAll()하지만content와selector반대.
대체 내용:
$(selector).replaceWith(content)
기능을 사용하여 내용을 대체
$(selector).replaceWith(function(index))
모든段落을 <h1>요소:
$("button").click(function(){ $("p").replaceWith("<h1>새 제목</h1>) });시험해보기‹/›
기능을 사용하여 내용을 대체
$("button").click(function(){ $("p").replaceWith(function(i){ return "<h2>이 요소는 인덱스 " + i + ".</h2>"; }); });시험해보기‹/›
파라미터 | 설명 |
---|---|
content | 삽입할 내용을 지정(HTML 태그를 포함할 수 있습니다) 가능한 값:
|
function(index) | 하위 함수 지정, 이 함수는 대체할 HTML 내용을 반환
|