Toggle a class value using Element.classList.toggle() method

Instead of using jQuery’s .toggleClass() method to add or remove classes from an element, I can use the Element.classList.toggle() method to achieve the similar goal. The method will return true if the value is successfully added to the element class, otherwise, it will return false.

It’s a perfectly valid choice for a fairly simple application.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s