How to add and remove Class on Html Elements in JQuery ?
Hello everyone !
I will explain very usefull function in Jquery that you can use it on your projects to solve some special problems. I use it often too that’s why I wanted to share that with you.
JQuery provide a lot of functions to solve our problems which easy to use.On the other hand, Jquery is one of most used development library. It gives us a lot of opportunities while developing. I will share link below to see a lot of graphics about Jquery and other technologies. Also you can see some graphics about to using JQuery by developers.
https://www.developereconomics.com/resources/graphs/
I suggest to use that awesome library in your projects. You can manage HTML elements with a lot of functions.
Let’s look back to our main topics.
Jquery has a functions to manage html element’s class attribute like adding and removing classes.
1- addClass()
addClass() is used to add class name to Html Elements. You will see below how is easy to giving a class name for elements. I will explain that with an easy example.
That’s all it. As you can see, we added a class name for our “p” element in our basic project but you can usee addClass() function on any Html Element.
2- removeClass()
remoClass() function is used for removing a class name from your html element. Let’s see how we use that with our another example.
As you can see on our basic project, we removed class name for our “p” element.
Finally, these 2 function is really useful for development. I hope, this will help you to solve your problems too.
Write Less, Do More !
Resources :
https://api.jquery.com/addclass/
Enjoy Your Coding !
Enver ŞANLI — Web Developer, Social Thinker and Farmer