728x90
반응형
replaceWith
target(변환될 엘리먼트)이 앞에 있다. (new Content: htmlString, element, array, jquery)
replaceAll
target이 뒤에 있다.
다음과 같이 버튼을 눌렀을 때 글자가 바뀐다. 각 태그를 썼을때 target의 위치의 차이를 잘 보자.
<body>
<body>
<div>
<p>DOM대체</p>
</div>
<button>바꾸기(replaceWith)</button>
<button>바꾸기(replaceAll)</button>
</body>
<script>
<script type="text/javascript">
$(function(){
//replaceWith: target(변환될 엘리먼트)이 앞에 있다.
$("button:first").click(function(){
$("p").replaceWith("<p><b>replaceWith</b></p>");
});
//replaceAll:target이 뒤에 있다.
$("button:last").click(function(){
$("<p><b>replaceAll</b></p>").replaceAll("p");
});
});
</script>
728x90
반응형
'Web > JQuery' 카테고리의 다른 글
[JQ]setInterval() (0) | 2020.08.04 |
---|---|
[JQ]내부삽입 (0) | 2020.08.03 |
[JQ]toggleClass (0) | 2020.08.03 |
[JQ]toggleClass (0) | 2020.08.03 |
[JQ]effect_03 (0) | 2020.08.03 |