사용자 도구

사이트 도구


wiki:javascript:javascript_note:jquery_dom

JavaScript / jQuery HTML DOM

  • description : JavaScript / jQuery HTML DOM
  • author : 오션
  • email : shlim@repia.com
  • lastupdate : 2021-04-14


Ref

Removing HTML Elements

HTML 요소를 제거합니다:

JQuery

<!DOCTYPE html>
<html lang="en">
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
 
  <h2>Remove an HTML Element with JQuery</h2>
 
  <h2 id="id01">Hello World!</h2>
  <h2 id="id02">Hello Sweden!!</h2>
 
  <script>
    $(document).ready(function () {
      $('#id02').remove();
    });
  </script>
 
</body>
</html>

JavaScript

<!DOCTYPE html>
<html lang="en">
<body>
 
  <h2>Remove an HTML Element with JavaScript</h2>
 
  <h2 id="id01">Hello World!</h2>
  <h2 id="id02">Hello Sweden!!</h2>
 
  <script>
    var element = document.getElementById("id01");
    element.parentNode.removeChild(element);
  </script>
 
</body>
</html>

Get Parent Element

HTML 요소의 부모를 반환합니다:

JQuery

<!DOCTYPE html>
<html lang="en">
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
 
  <h1>Getting Parent HTML Element with JQuery</h1>
 
  <h2 id="01">Hello World!</h2>
  <h2 id="02">Hello Sweden!!</h2>
  <h2 id="03">Hello Austria!!!</h2>
 
  <p id="demo"></p>
 
  <script>
    $(document).ready(function () {
      var myParent = $("#02").parent();
      $("#demo").text(myParent.prop("nodeName"));
    });
  </script>
 
</body>
</html>

JavaScript

<!DOCTYPE html>
<html lang="en">
<body>
 
  <h1>Getting Parent HTML Element with JavaScript</h1>
 
  <h2 id="01">Hello World!</h2>
  <h2 id="02">Hello Sweden!!</h2>
  <h2 id="03">Hello Austria!!!</h2>
 
  <p id="demo"></p>
 
  <script>
    var myParent = document.getElementById("02").parentNode;
    document.getElementById("demo").innerHTML = myParent.nodeName;
  </script>
 
</body>
</html>
/volume1/web/dokuwiki/data/pages/wiki/javascript/javascript_note/jquery_dom.txt · 마지막으로 수정됨: 2023/01/13 18:44 (바깥 편집)