Skip to content

Commit

Permalink
DOM Done
Browse files Browse the repository at this point in the history
  • Loading branch information
umarsayed12 committed May 4, 2024
1 parent fa1f8f7 commit 97236ad
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions DOM/edit_elements.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edit Elements in DOM</title>
</head>
<body style="background-color: slategray; color: #fff; padding: 10px;">
<li class="lang">
JavaScript
</li>
</body>
<script>
function addtext(language){
const li = document.createElement("li");
li.appendChild(document.createTextNode(language));
document.body.appendChild(li);
}

addtext("Python");
addtext("HTML");
addtext("CSS");

//EDIT

const li = document.querySelector('li:nth-child()');
const newel = document.createElement("li");
newel.appendChild(document.createTextNode("C++"));
li.replaceWith(newel);

//Remove

const el = document.querySelector('li:nth-child(even)');
el.remove();

</script>
</html>

0 comments on commit 97236ad

Please sign in to comment.