create-modify-element - Add removeChild section

This commit is contained in:
2020-10-16 13:39:34 +05:30
parent bd3ea6992e
commit 07c5772b7c
+17 -2
View File
@@ -19,7 +19,7 @@ This method returns the **first element that matches the CSS selector**. If no m
```js ```js
document.querySelector(selector); document.querySelector(selector);
// Ex- .container > .box // <div className="box" />
document.querySelector(".box"); // returns .box document.querySelector(".box"); // returns .box
document.querySelector(".not-found"); // null document.querySelector(".not-found"); // null
``` ```
@@ -147,5 +147,20 @@ eleDiv.appendChild(eleH1)
<MDN title="appendChild" url="https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild" /> <MDN title="appendChild" url="https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild" />
### 4. appendChild() ### 4. removeChild()
`Element.removeChild(childElement)`
This method tries to remove a child element from the parent and returns the removed node.
If the element to be removed is not a child of the parent element, it throws a `NotFoundError` DOMException.
```js
// <div class="parent">
// <div class="child"/>
// </div>
parentEle.removeChild(childEle)
```
<MDN title="removeChild" url="https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild" />