jQuery DOM

Example

<!DOCTYPE html>
<html>
<head>
<script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js”></script>
</head>
<body>

<h2>Remove an HTML Element</h2>

<h2 id=”id01″>Hello World!</h2>
<h2 id=”id02″>Hello Sweden!</h2>

<script>
$(document).ready(function() {
$(“#id02”).remove();
});
</script>

</body>
</html>

Output

Remove an HTML Element

Hello World!

Hello Sweden!

Example

<!DOCTYPE html>
<html>
<body>

<h2>Remove an HTML Element</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>

Output

Remove an HTML Element

Hello World!

Hello Sweden!

Updated: February 13, 2019 — 6:13 am
Java Script © 2019