diff --git a/README.md b/README.md
index 46f01c489..c708e58a3 100644
--- a/README.md
+++ b/README.md
@@ -91,9 +91,11 @@
* [`elementIsVisibleInViewport`](#elementisvisibleinviewport)
* [`getScrollPosition`](#getscrollposition)
* [`getURLParameters`](#geturlparameters)
+* [`hasClass`](#hasclass)
* [`httpsRedirect`](#httpsredirect)
* [`redirect`](#redirect)
* [`scrollToTop`](#scrolltotop)
+* [`toggleClass`](#toggleclass)
@@ -1762,6 +1764,29 @@ getURLParameters('http://url.com/page?name=Adam&surname=Smith'); // {name: 'Adam
[⬆ Back to top](#table-of-contents)
+### hasClass
+
+Returns `true` if the element has the specified class, `false` otherwise.
+
+Use `element.classList.contains()` to check if the element has the specified class.
+
+```js
+const hasClass = (el, className) => el.classList.contains(className);
+```
+
+Examples
+
+```js
+hasClass(document.querySelector('p.special'), 'special'); // true
+```
+
+Examples
+
+```js
+toggleClass(document.querySelector('p.special'), 'special'); // The paragraph will not have the 'special' class anymore
+```
+
+
location.search as the argument to apply to the current
getURLParameters('http://url.com/page?name=Adam&surname=Smith'); // {name: 'Adam', surname: 'Smith'}
+Returns true if the element has the specified class, false otherwise.
Use element.classList.contains() to check if the element has the specified class.
const hasClass = (el, className) => el.classList.contains(className);
+
+hasClass(document.querySelector('p.special'), 'special'); // true
+
Redirects the page to HTTPS if its currently in HTTP. Also, pressing the back button doesn't take it back to the HTTP page as its replaced in the history.
Use location.protocol to get the protocol currently being used. If it's not HTTPS, use location.replace() to replace the existing page with the HTTPS version of the page. Use location.href to get the full address, split it with String.split() and remove the protocol part of the URL.
window.requestAnima
scrollToTop();
+Toggle a class for an element.
+Use element.classList.toggle() to toggle the specified class for the element.
const toggleClass = (el, className) => el.classList.toggle(className);
+
+toggleClass(document.querySelector('p.special'), 'special'); // The paragraph will not have the 'special' class anymore
+
Returns the difference (in days) between two dates.
diff --git a/snippets/hasClass.md b/snippets/hasClass.md index 3a332d169..eb3fc086d 100644 --- a/snippets/hasClass.md +++ b/snippets/hasClass.md @@ -9,5 +9,5 @@ const hasClass = (el, className) => el.classList.contains(className); ``` ```js -hasClass(document.querySelector('p.special'),'special') // true +hasClass(document.querySelector('p.special'), 'special'); // true ``` diff --git a/snippets/toggleClass.md b/snippets/toggleClass.md index fb773f261..eb9f17504 100644 --- a/snippets/toggleClass.md +++ b/snippets/toggleClass.md @@ -9,5 +9,5 @@ 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 ```