HTML 요소를 제거합니다:
<!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>
<!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>
HTML 요소의 부모를 반환합니다:
<!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>
<!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>