mirror of
https://github.com/bendtherules/UiQuestions.git
synced 2026-08-18 13:52:50 +00:00
create-modify-element - Put function signatures at top of each api
This commit is contained in:
@@ -13,11 +13,11 @@ import MDN from "../components/MDNBadge"
|
|||||||
|
|
||||||
### 1. querySelector()
|
### 1. querySelector()
|
||||||
|
|
||||||
|
`document.querySelector(selector) : Element | null`
|
||||||
|
|
||||||
This method returns the **first element that matches the CSS selector**. If no match is found, it returns `null`.
|
This method returns the **first element that matches the CSS selector**. If no match is found, it returns `null`.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
document.querySelector(selector);
|
|
||||||
|
|
||||||
// <div className="box" />
|
// <div className="box" />
|
||||||
document.querySelector(".box"); // returns .box
|
document.querySelector(".box"); // returns .box
|
||||||
document.querySelector(".not-found"); // null
|
document.querySelector(".not-found"); // null
|
||||||
@@ -25,7 +25,7 @@ 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, this is very useful.
|
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.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Example - .outer > .inner
|
// Example - .outer > .inner
|
||||||
@@ -40,6 +40,8 @@ document.querySelector(".not-found"); // null
|
|||||||
|
|
||||||
### 2. querySelectorAll()
|
### 2. querySelectorAll()
|
||||||
|
|
||||||
|
`document.querySelectorAll(selector) : NodeList`
|
||||||
|
|
||||||
This method returns **all the elements that match** the specified CSS selector.
|
This method returns **all the elements that match** the specified CSS selector.
|
||||||
|
|
||||||
It returns a **static NodeList**, which contains the matching elements. If no match is found, it returns empty NodeList.
|
It returns a **static NodeList**, which contains the matching elements. If no match is found, it returns empty NodeList.
|
||||||
@@ -90,10 +92,10 @@ document.createElement("div")
|
|||||||
|
|
||||||
### 4. setAttribute()
|
### 4. setAttribute()
|
||||||
|
|
||||||
It sets a attribute on the current element.
|
|
||||||
|
|
||||||
`Element.setAttribute(name, value)`
|
`Element.setAttribute(name, value)`
|
||||||
|
|
||||||
|
It sets a attribute on the current element.
|
||||||
|
|
||||||
`name` - name of the attribute to add. Ex- "type".
|
`name` - name of the attribute to add. Ex- "type".
|
||||||
`value` - value of the attribute. Ex- "text".
|
`value` - value of the attribute. Ex- "text".
|
||||||
|
|
||||||
@@ -108,10 +110,10 @@ ele.setAttribute("type", "text")
|
|||||||
|
|
||||||
### 5. appendChild()
|
### 5. appendChild()
|
||||||
|
|
||||||
It inserts a new element as the last child of the parent element.
|
|
||||||
|
|
||||||
`Element.appendChild(newElement)`
|
`Element.appendChild(newElement)`
|
||||||
|
|
||||||
|
It inserts a new element as the last child of the parent element.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var eleDiv = document.createElement("div")
|
var eleDiv = document.createElement("div")
|
||||||
var eleH1 = document.createElement("h1")
|
var eleH1 = document.createElement("h1")
|
||||||
|
|||||||
Reference in New Issue
Block a user