diff --git a/snippets/getStyle.md b/snippets/getStyle.md new file mode 100644 index 000000000..40b744a2b --- /dev/null +++ b/snippets/getStyle.md @@ -0,0 +1,13 @@ +### getStyle + +Returns the value of a CSS rule for the specified element. + +Use `Window.getComputedStyle()` to get the value of the CSS rule for the specified element. + +```js +const getStyle = (el, ruleName) => getComputedStyle(el)[ruleName]; +``` + +```js +getStyle(document.querySelector('p'), 'font-size') // '16px' +``` diff --git a/snippets/setStyle.md b/snippets/setStyle.md new file mode 100644 index 000000000..7ac9460af --- /dev/null +++ b/snippets/setStyle.md @@ -0,0 +1,13 @@ +### setStyle + +Sets the value of a CSS rule for the specified element. + +Use `element.style` to set the value of the CSS rule for the specified element to `value`. + +```js +const setStyle = (el, ruleName, value) => el.style[ruleName] = value; +``` + +```js +setStyle(document.querySelector('p'), 'font-size', '20px') // The first
element on the page will have a font-size of 20px +``` diff --git a/tag_database b/tag_database index db0e12548..b9b43e79c 100644 --- a/tag_database +++ b/tag_database @@ -50,6 +50,7 @@ functionName:function gcd:math getDaysDiffBetweenDates:date getScrollPosition:browser +getStyle:browser getType:utility getURLParameters:browser groupBy:array @@ -112,6 +113,7 @@ sample:array scrollToTop:browser sdbm:utility select:object +setStyle:browser shallowClone:object show:browser shuffle:array