To replace a class of an element with a new one, you use the replace() method of the classList property of the element.
Toggle password visibility
In order to show the password, we turn the password element to an usual textbox whose type attribute is text.
Get a formatted list of months
Here’s a trick for getting back a formatted month name (like January or Jan).
Insert an HTML string before the start of the specified element
Use Element.insertAdjacentHTML() with a position of ‘beforebegin’ to parse htmlString and insert it before the start of el.
Check If an Element contains a Class
To check if an element contains a class, you use the contains() method of the classList property of the element.
Clone an element
Using the cloneNode(true) method will deep copy a given element.
Get the date for a specific day of the week
Here’s a way to get the date for the next occurrence of a specific day of the week.
Remove an element from the DOM
Use Element.parentNode to get the given element’s parent node. Use Element.removeChild() to remove the given element from its parent node.
Toggle a Class of an Element
To toggle a class of an element, you use the toggle() method of the classList property of the element.
Count the number of characters of a textarea
Count the number of characters by handling the input event which is triggered if the value of element is changed.