mirror of
https://github.com/bendtherules/UiQuestions.git
synced 2026-08-18 13:52:50 +00:00
Make changes as per code feedback
This commit is contained in:
@@ -11,8 +11,7 @@ import MDN from "../components/MDNBadge"
|
|||||||
|
|
||||||
:::note DOM interfaces
|
:::note DOM interfaces
|
||||||
Every kind of **DOM** node is represented by an interface based on **Node** interface.
|
Every kind of **DOM** node is represented by an interface based on **Node** interface.
|
||||||
**Element, Document and DocumentFragment** interfaces inherit from Node.
|
**Element, Document and DocumentFragment** interfaces inherit from Node. More about DOM interfaces [here](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model)
|
||||||
More about DOM interfaces [here](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model)
|
|
||||||
:::
|
:::
|
||||||
|
|
||||||
## Finding elements
|
## Finding elements
|
||||||
@@ -31,13 +30,13 @@ document.querySelector(".not-found"); // null
|
|||||||
|
|
||||||
<Accordion>
|
<Accordion>
|
||||||
<Admonition type="note" title="Extra">
|
<Admonition type="note" title="Extra">
|
||||||
This method is also available on all DOM nodes. If you want to look within a specific element, just use `ele.querySelector()` on the parent element.
|
Besides <b>Document</b>, this method is also available on <b>Element</b> and <b>DocumentFragment</b>.<br/>
|
||||||
|
If you want to look within a specific element, just use <code>ele.querySelector()</code> on the parent element.<br/>
|
||||||
|
If you want to look within a specific fragment, just use <code>df.querySelector()</code> on the parent fragment.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Example - .outer > .inner
|
// Example - outer is a parent element/fragment.
|
||||||
outerEle.addEventListener((ev) => {
|
let innerEle = outer.querySelector(".inner");
|
||||||
let innerEle = ev.target.querySelector(".inner");
|
|
||||||
});
|
|
||||||
```
|
```
|
||||||
</Admonition>
|
</Admonition>
|
||||||
</Accordion>
|
</Accordion>
|
||||||
@@ -66,6 +65,19 @@ for (let p of paras) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
<Accordion>
|
||||||
|
<Admonition type="note" title="Extra">
|
||||||
|
Besides <b>Document</b>, this method is also available on <b>Element</b> and <b>DocumentFragment</b>.<br/>
|
||||||
|
If you want to look for list of elements within specific element, just use <code>ele.querySelectorAll()</code> on the parent element.<br/>
|
||||||
|
If you want to look for list of elements within specific fragment, just use <code>df.querySelectorAll()</code> on the parent fragment.
|
||||||
|
|
||||||
|
```js
|
||||||
|
// Example - outer is a parent element/fragment.
|
||||||
|
let innerEles = outer.querySelectorAll(".inner");
|
||||||
|
```
|
||||||
|
</Admonition>
|
||||||
|
</Accordion>
|
||||||
|
|
||||||
<MDN title="querySelectorAll" url="https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll" />
|
<MDN title="querySelectorAll" url="https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll" />
|
||||||
|
|
||||||
## Create / insert element
|
## Create / insert element
|
||||||
@@ -132,13 +144,13 @@ eleDiv.appendChild(eleH1)
|
|||||||
|
|
||||||
<Accordion title="Edge cases and alternative">
|
<Accordion title="Edge cases and alternative">
|
||||||
<Admonition type="note" title="If it already has a parent">
|
<Admonition type="note" title="If it already has a parent">
|
||||||
If newElement is already a child of another element,
|
If newNode is already a child of another node,
|
||||||
then it is removed from its existing parent and then added to the new parent.
|
then it is removed from its existing parent and then added to the new parent.
|
||||||
</Admonition>
|
</Admonition>
|
||||||
|
|
||||||
<Admonition type="note" title="If it is DocumentFragment">
|
<Admonition type="note" title="If it is DocumentFragment">
|
||||||
If newElement is a DocumentFragment, then - instead of adding the fragment itself as a child,
|
If newNode is a DocumentFragment, then - instead of adding the fragment itself as a child,
|
||||||
the entire content of the fragment is added as children of the parent element.
|
the entire content of the fragment is added as children of the parent node.
|
||||||
</Admonition>
|
</Admonition>
|
||||||
|
|
||||||
<Admonition type="note" title=".append()">
|
<Admonition type="note" title=".append()">
|
||||||
|
|||||||
Reference in New Issue
Block a user