Update some browser snippet descriptions
This commit is contained in:
@ -5,7 +5,7 @@ tags: browser,url,beginner
|
|||||||
|
|
||||||
Returns the current URL.
|
Returns the current URL.
|
||||||
|
|
||||||
Use `window.location.href` to get current URL.
|
Use `window.location.href` to get the current URL.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const currentURL = () => window.location.href;
|
const currentURL = () => window.location.href;
|
||||||
|
|||||||
@ -12,5 +12,6 @@ const insertAfter = (el, htmlString) => el.insertAdjacentHTML('afterend', htmlSt
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
insertAfter(document.getElementById('myId'), '<p>after</p>'); // <div id="myId">...</div> <p>after</p>
|
insertAfter(document.getElementById('myId'), '<p>after</p>');
|
||||||
|
// <div id="myId">...</div> <p>after</p>
|
||||||
```
|
```
|
||||||
@ -12,5 +12,6 @@ const insertBefore = (el, htmlString) => el.insertAdjacentHTML('beforebegin', ht
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
insertBefore(document.getElementById('myId'), '<p>before</p>'); // <p>before</p> <div id="myId">...</div>
|
insertBefore(document.getElementById('myId'), '<p>before</p>');
|
||||||
|
// <p>before</p> <div id="myId">...</div>
|
||||||
```
|
```
|
||||||
@ -3,7 +3,7 @@ title: setStyle
|
|||||||
tags: browser,beginner
|
tags: browser,beginner
|
||||||
---
|
---
|
||||||
|
|
||||||
Sets the value of a CSS rule for the specified element.
|
Sets the value of a CSS rule for the specified HTML element.
|
||||||
|
|
||||||
Use `element.style` to set the value of the CSS rule for the specified element to `val`.
|
Use `element.style` to set the value of the CSS rule for the specified element to `val`.
|
||||||
|
|
||||||
@ -12,5 +12,6 @@ const setStyle = (el, ruleName, val) => (el.style[ruleName] = val);
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
setStyle(document.querySelector('p'), 'font-size', '20px'); // The first <p> element on the page will have a font-size of 20px
|
setStyle(document.querySelector('p'), 'font-size', '20px');
|
||||||
|
// The first <p> element on the page will have a font-size of 20px
|
||||||
```
|
```
|
||||||
@ -3,7 +3,7 @@ title: toggleClass
|
|||||||
tags: browser,beginner
|
tags: browser,beginner
|
||||||
---
|
---
|
||||||
|
|
||||||
Toggle a class for an element.
|
Toggles a class for an HTML element.
|
||||||
|
|
||||||
Use `element.classList.toggle()` to toggle the specified class for the element.
|
Use `element.classList.toggle()` to toggle the specified class for the element.
|
||||||
|
|
||||||
@ -12,5 +12,6 @@ const toggleClass = (el, className) => el.classList.toggle(className);
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
toggleClass(document.querySelector('p.special'), 'special'); // The paragraph will not have the 'special' class anymore
|
toggleClass(document.querySelector('p.special'), 'special');
|
||||||
|
// The paragraph will not have the 'special' class anymore
|
||||||
```
|
```
|
||||||
Reference in New Issue
Block a user