반응형
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script>
      $(document).ready(function() {
        //p태그를 h2태그로 전체 교체
        $("#replaceAll").click(function() {
          $("<h2>replaceAll</h2>").replaceAll("p");
        });
        //p tag의 first를 하나씩 replaceWith로 교체
        $("#replaceWith").click(function() {
          $("p:first").replaceWith("replaceWith");
        });
      });
    </script>
    <title>Document</title>
  </head>
  <body>
    <p>This is a paragraph.</p>
    <p>This is another paragraph</p>
    <p>This is another paragraph</p>

    <button id="replaceAll">replaceAll</button>
    <button id="replaceWith">replaceWith</button>
  </body>
</html>
반응형

'2020 > JQuery' 카테고리의 다른 글

JQuery unbind(이벤트해제)  (0) 2020.02.28
JQuery detach, empty, remove, 요소제거  (0) 2020.02.28
JQuery 속성 값 입력  (0) 2020.02.28
JQuery selectbox 확인  (0) 2020.02.28
JQuery 객체추가  (0) 2020.02.28
블로그 이미지

꽃꽂이하는개발자

,