사용자 도구

사이트 도구


wiki:javascript:jquery:jquery_note:jquery_references_traversing:jquery_contents_method

문서의 이전 판입니다!


jQuery contents() Method

  • description : jQuery contents() Method
  • author : 오션
  • email : shlim@repia.com
  • lastupdate : 2022-10-24 Mon


The source of this article

Definition and Usage

contents() 메서드는 선택한 요소의 텍스트 및 주석 노드를 포함한 모든 직계 자식을 반환합니다.

텍스트 노드는 요소가 표시하는 실제 텍스트입니다.

이 메서드는 텍스트 및 주석 노드도 반환한다는 점을 제외하고 children() 메서드와 유사합니다.
Contents() 메서드는 iframe이 동일한 도메인에 있는 경우 HTML에도 액세스할 수 있습니다.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <title>jquery contents()</title>
  </head>
  <body>
    <div>
      <em>Hello World! What a beautiful day!</em>
    </div>
 
    <p>
      In this example, by clicking on the button, we search for all the text
      nodes inside the div element and wrap them with a b element.
    </p>
 
    <button>Find all text nodes in div and wrap them.</button><br />
    <script>
      $(document).ready(function () {
        $("button").click(function () {
          $("div").contents().filter("em").wrap("<b />");
        });
      });
    </script>
  </body>
</html>
/volume1/web/dokuwiki/data/attic/wiki/javascript/jquery/jquery_note/jquery_references_traversing/jquery_contents_method.1666576524.txt.gz · 마지막으로 수정됨: 2022/10/24 10:55 저자 emblim98