Update some browser snippet descriptions

This commit is contained in:
Angelos Chalaris
2020-03-06 09:57:40 +02:00
parent 6ae9cd2fcb
commit 6f77474128
5 changed files with 16 additions and 12 deletions

View File

@ -5,7 +5,7 @@ tags: browser,url,beginner
Returns the current URL.
Use `window.location.href` to get current URL.
Use `window.location.href` to get the current URL.
```js
const currentURL = () => window.location.href;
@ -13,4 +13,4 @@ const currentURL = () => window.location.href;
```js
currentURL(); // 'https://google.com'
```
```

View File

@ -12,5 +12,6 @@ const insertAfter = (el, htmlString) => el.insertAdjacentHTML('afterend', htmlSt
```
```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>
```

View File

@ -12,5 +12,6 @@ const insertBefore = (el, htmlString) => el.insertAdjacentHTML('beforebegin', ht
```
```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>
```

View File

@ -3,7 +3,7 @@ title: setStyle
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`.
@ -12,5 +12,6 @@ const setStyle = (el, ruleName, val) => (el.style[ruleName] = val);
```
```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
```

View File

@ -3,7 +3,7 @@ title: toggleClass
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.
@ -12,5 +12,6 @@ const toggleClass = (el, className) => el.classList.toggle(className);
```
```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
```