{"id":7081,"date":"2015-09-21T12:15:36","date_gmt":"2015-09-21T09:15:36","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=7081"},"modified":"2017-12-21T16:14:09","modified_gmt":"2017-12-21T14:14:09","slug":"jquery-add-remove-class-example","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/","title":{"rendered":"jQuery Add\/Remove Class Example"},"content":{"rendered":"<p>In this example, we&#8217;ll go through jQuery <code>.addClass()<\/code> and <code>.removeClass()<\/code> methods. jQuery provides a seamless, easy and efficent way to add or remove classes to specific DOM elements and trigger these events on the various listening events it provides like <code>click<\/code>, <code>mouseover<\/code>, <code>mouseleave<\/code> ect.<\/p>\n<p>These methods are very useful to dynamically change content based on your cases, and gives your website a rather interactive and engaging user experience. From changing styles and colors to animations, it provides powerful ways to get you going.<\/p>\n<p>You&#8217;ll be able to access these methods just by including the jQuery library in your HTML document.<br \/>\n&nbsp;<br \/>\n[ulp id=&#8217;qGGDqWnle19VavkM&#8217;]<\/p>\n<h2>1. Basic Document Setup<\/h2>\n<p>To begin, create a new HTML document and add the following basic syntax inside:<\/p>\n<pre class=\"brush:xml\">\r\n&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n\t&lt;title&gt;jQuery Add\/Remove Class Example&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;!-- STYLE SECTION  --&gt;\r\n&lt;style type=\"text\/css\"&gt;\r\n\r\n&lt;\/style&gt;\r\n\r\n\r\n&lt;!-- HTML SECTION  --&gt;\r\n\r\n\r\n&lt;!-- JAVASCRIPT SECTION  --&gt;\r\n&lt;script src=\"jquery-1.11.3.min.js\"&gt;&lt;\/script&gt;\r\n\r\n&lt;script type=\"text\/javascript\"&gt;\r\n\r\n&lt;\/script&gt;\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>Also, let&#8217;s create some elements with classes and define properties for these classes in CSS. For now, there will be only one element and two classes:<\/p>\n<pre class=\"brush:xml\">\r\n&lt;!-- HTML SECTION  --&gt;\r\n&lt;div class=\"element\"&gt;I am going to get classes added or removed!&lt;div&gt;\r\n<\/pre>\n<p>For now, we&#8217;d have this view:<br \/>\n<figure id=\"attachment_7102\" aria-describedby=\"caption-attachment-7102\" style=\"width: 820px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-1.jpg\"><img decoding=\"async\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-1.jpg\" alt=\"Basic Element View\" width=\"820\" height=\"99\" class=\"size-full wp-image-7102\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-1.jpg 820w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-1-300x36.jpg 300w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/a><figcaption id=\"caption-attachment-7102\" class=\"wp-caption-text\">Basic Element View<\/figcaption><\/figure><br \/>\nAlongside with this element, let&#8217;s add two classes, one for styling and another for shaping:<\/p>\n<pre class=\"brush:css\">\r\n&lt;!-- STYLE SECTION  --&gt;\r\n&lt;style type=\"text\/css\"&gt;\r\n    .style {\r\n        font-family: \"Clear Sans\";\r\n        font-size: 1.5em;\r\n        color: #AE0001;\r\n        font-style: oblique;\r\n        padding: 1em;\r\n    }\r\n    .shape {\r\n        width: 25em;\r\n        height: 3em;\r\n        border: 0.1em solid #2c3e50;\r\n        margin: 5em;\r\n        line-height: 3em;\r\n        text-align: center;\r\n    }\r\n    .decoration {\r\n        text-decoration: underline;\r\n        font-size: 1.2em;\r\n        padding: 1em;\r\n        width: 15em;\r\n    }\r\n    .color {\r\n        color: #e74c3c;\r\n    }\r\n    .background {\r\n        background-color: #ecf0f1;\r\n        font-size: 1.2em;\r\n        padding: 1em;\r\n        width: 15em;\r\n    }\r\n&lt;\/style&gt;\r\n<\/pre>\n<p>Next, we&#8217;ll continue adding and removing classes that we have.<\/p>\n<h2>2. .addClass() and .removeClass() Methods<\/h2>\n<h3>2.1 Add Class<\/h3>\n<p>The <code>addClass()<\/code> method adds the specified class(es) to each element in the set of matched elements:<\/p>\n<p>1. <code>.addClass(\"className\")<\/code>, in which <code>className<\/code> is a string containing one or more space-separated classes to be added to the class attribute of each matched element.<\/p>\n<p>2. <code>.addClass(function)<\/code> in which <code>className<\/code> A function returning one or more space-separated class names to be added to the existing class name(s). Receives the index position of the element in the set and the existing class name(s) as arguments. Within the function, this refers to the current element in the set.<\/p>\n<p>Now using jQuery, we can add a class to our <code>.element<\/code>:<\/p>\n<pre class=\"brush:java\">\r\n&lt;!-- JAVASCRIPT SECTION  --&gt;\r\n&lt;script type=\"text\/javascript\"&gt;\r\n    $('.element').addClass('style');\r\n&lt;\/script&gt;\r\n<\/pre>\n<p>Easy as that, just selected the DOM element and added a class.<br \/>\n<figure id=\"attachment_7105\" aria-describedby=\"caption-attachment-7105\" style=\"width: 820px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-2.jpg\"><img decoding=\"async\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-2.jpg\" alt=\"Element View after Adding the &#039;style&#039; Class\" width=\"820\" height=\"105\" class=\"size-full wp-image-7105\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-2.jpg 820w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-2-300x38.jpg 300w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/a><figcaption id=\"caption-attachment-7105\" class=\"wp-caption-text\">Element View after Adding the &#8216;style&#8217; Class<\/figcaption><\/figure><br \/>\nWe added the &#8216;.style&#8217; class, the same goes for &#8216;.shape&#8217; class and we&#8217;d have this view:<br \/>\n<figure id=\"attachment_7107\" aria-describedby=\"caption-attachment-7107\" style=\"width: 820px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-3.jpg\"><img decoding=\"async\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-3.jpg\" alt=\"Added the &#039;.shape&#039; Class\" width=\"820\" height=\"105\" class=\"size-full wp-image-7107\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-3.jpg 820w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-3-300x38.jpg 300w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/a><figcaption id=\"caption-attachment-7107\" class=\"wp-caption-text\">Added the &#8216;.shape&#8217; Class<\/figcaption><\/figure><br \/>\nBut what is interesting, is that you can have more than one class added, just by leaving a blank space between them:<\/p>\n<pre class=\"brush:java\">\r\n&lt;!-- JAVASCRIPT SECTION  --&gt;\r\n&lt;script type=\"text\/javascript\"&gt;\r\n    $('.element').addClass('style shape');\r\n&lt;\/script&gt;\r\n<\/pre>\n<figure id=\"attachment_7110\" aria-describedby=\"caption-attachment-7110\" style=\"width: 820px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-4.jpg\"><img decoding=\"async\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-4.jpg\" alt=\"Multiple Classes Added\" width=\"820\" height=\"251\" class=\"size-full wp-image-7110\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-4.jpg 820w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-4-300x92.jpg 300w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/a><figcaption id=\"caption-attachment-7110\" class=\"wp-caption-text\">Multiple Classes Added<\/figcaption><\/figure>\n<h3>2.2 Remove Class<\/h3>\n<p>Similarily, .removeClass() removes a (or some) class\/es from an element. To show this, add a new HTML element:<\/p>\n<pre class=\"brush:xml\">\r\n&lt;!-- HTML SECTION  --&gt;\r\n&lt;p class=\"decoration color background\"&gt;I need to get rid of some classes&lt;\/p&gt;\r\n<\/pre>\n<p>In the JS section, let&#8217;s remove two of these classes:<\/p>\n<pre class=\"brush:java\">\r\n&lt;!-- JAVASCRIPT SECTION  --&gt;\r\n&lt;script type=\"text\/javascript\"&gt;\r\n    $('.element').addClass('style shape');\r\n&lt;\/script&gt;\r\n<\/pre>\n<p>The view we&#8217;d get is this:<br \/>\n<figure id=\"attachment_7113\" aria-describedby=\"caption-attachment-7113\" style=\"width: 820px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-5.jpg\"><img decoding=\"async\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-5.jpg\" alt=\"Remove Class Method\" width=\"820\" height=\"251\" class=\"size-full wp-image-7113\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-5.jpg 820w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-5-300x92.jpg 300w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/a><figcaption id=\"caption-attachment-7113\" class=\"wp-caption-text\">Remove Class Method<\/figcaption><\/figure><\/p>\n<h2>3. Adding or Removing Classes on Event Listeners<\/h2>\n<p>You can trigger classes only when a specific event listener happens to become true. Let&#8217;s add some elements:<\/p>\n<pre class=\"brush:xml\">\r\n&lt;!-- HTML SECTION  --&gt;\r\n&lt;h2 class=\"decoration\"&gt;This is a click event add class.&lt;\/h2&gt;\r\n<\/pre>\n<pre class=\"brush:java\">\r\n&lt;!-- JAVASCRIPT SECTION  --&gt;\r\n&lt;script type=\"text\/javascript\"&gt;\r\n    $('article').hide();\r\n    $('h2').click(function(e){\r\n        e.preventDefault();\r\n        $(this).addClass('shape color');\r\n        $(this).removeClass('decoration');\r\n    });\r\n&lt;\/script&gt;\r\n<\/pre>\n<p>The result would be two classes added and one removed after click like so:<br \/>\n<figure id=\"attachment_7118\" aria-describedby=\"caption-attachment-7118\" style=\"width: 820px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-7.jpg\"><img decoding=\"async\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-7.jpg\" alt=\"Trigger Add or Remove Class on Event Listener!\" width=\"820\" height=\"293\" class=\"size-full wp-image-7118\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-7.jpg 820w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-7-300x107.jpg 300w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><\/a><figcaption id=\"caption-attachment-7118\" class=\"wp-caption-text\">Trigger Add or Remove Class on Event Listener!<\/figcaption><\/figure><\/p>\n<h3>Toggle Classes on Event Listeners<\/h3>\n<p>You can use <code>.toggleClass()<\/code> to toggle between the two states of an element, with and without classes like this:<\/p>\n<pre class=\"brush:java\">\r\n&lt;!-- JAVASCRIPT SECTION  --&gt;\r\n&lt;script type=\"text\/javascript\"&gt;\r\n    $('article').hide();\r\n    $('h2').click(function(e){\r\n        e.preventDefault();\r\n        $(this).toggleClass('shape color');\r\n    });\r\n&lt;\/script&gt;\r\n<\/pre>\n<p>The result would be:<br \/>\n<figure id=\"attachment_7120\" aria-describedby=\"caption-attachment-7120\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-6.gif\"><img decoding=\"async\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/add-remove-class-6.gif\" alt=\"Toggle Class Example\" width=\"800\" height=\"158\" class=\"size-full wp-image-7120\" \/><\/a><figcaption id=\"caption-attachment-7120\" class=\"wp-caption-text\">Toggle Class Example<\/figcaption><\/figure><\/p>\n<h2>4. Conclusion<\/h2>\n<p>To conclude, the jQuery methods for adding or removing classes are just right whenever it feels useful. You can actually add or remove content (by adding or removing classes), change the view on mouse or keyboard event ect. It is a process where you can try a lot and see how it best fits to what you want to achieve. I use it a lot when adding classes from a third party CSS stylesheet like an animation one, to animate elements <code>mouseover<\/code> or <code>mouseleave<\/code>. It is up to you.<\/p>\n<h2>5. Download<\/h2>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/jQuery-Add-Remove-Class.zip\"><strong>jQuery Add\/Remove Class<\/strong><\/a>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this example, we&#8217;ll go through jQuery .addClass() and .removeClass() methods. jQuery provides a seamless, easy and efficent way to add or remove classes to specific DOM elements and trigger these events on the various listening events it provides like click, mouseover, mouseleave ect. These methods are very useful to dynamically change content based on &hellip;<\/p>\n","protected":false},"author":75,"featured_media":919,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-7081","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jquery"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>jQuery Add\/Remove Class Example - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"In this example, we&#039;ll go through jQuery .addClass() and .removeClass() methods. jQuery provides a seamless, easy and efficent way to add or remove\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"jQuery Add\/Remove Class Example - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"In this example, we&#039;ll go through jQuery .addClass() and .removeClass() methods. jQuery provides a seamless, easy and efficent way to add or remove\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/fabiocimo\" \/>\n<meta property=\"article:published_time\" content=\"2015-09-21T09:15:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-12-21T14:14:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Fabio Cimo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fabiocimo\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Fabio Cimo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/\"},\"author\":{\"name\":\"Fabio Cimo\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/1dfb88b4a8d08c37a6080311fd330a22\"},\"headline\":\"jQuery Add\/Remove Class Example\",\"datePublished\":\"2015-09-21T09:15:36+00:00\",\"dateModified\":\"2017-12-21T14:14:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/\"},\"wordCount\":631,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg\",\"articleSection\":[\"jQuery\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/\",\"name\":\"jQuery Add\/Remove Class Example - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg\",\"datePublished\":\"2015-09-21T09:15:36+00:00\",\"dateModified\":\"2017-12-21T14:14:09+00:00\",\"description\":\"In this example, we'll go through jQuery .addClass() and .removeClass() methods. jQuery provides a seamless, easy and efficent way to add or remove\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"jQuery\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/jquery\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"jQuery Add\/Remove Class Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/1dfb88b4a8d08c37a6080311fd330a22\",\"name\":\"Fabio Cimo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b3df055f2e1b62e238889fafbb16121c68aab1adcd11af670e185cafae201b3b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b3df055f2e1b62e238889fafbb16121c68aab1adcd11af670e185cafae201b3b?s=96&d=mm&r=g\",\"caption\":\"Fabio Cimo\"},\"description\":\"Fabio is a passionate student in web tehnologies including front-end (HTML\/CSS) and web design. He likes exploring as much as possible about the world wide web and how it can be more productive for us all. Currently he studies Computer Engineering, at the same time he works as a freelancer on both web programming and graphic design.\",\"sameAs\":[\"https:\/\/www.facebook.com\/fabiocimo\",\"https:\/\/al.linkedin.com\/in\/fabiocimo\",\"https:\/\/x.com\/fabiocimo\",\"https:\/\/www.youtube.com\/fabiocimo1\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/fabio-cimo\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"jQuery Add\/Remove Class Example - Web Code Geeks - 2026","description":"In this example, we'll go through jQuery .addClass() and .removeClass() methods. jQuery provides a seamless, easy and efficent way to add or remove","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/","og_locale":"en_US","og_type":"article","og_title":"jQuery Add\/Remove Class Example - Web Code Geeks - 2026","og_description":"In this example, we'll go through jQuery .addClass() and .removeClass() methods. jQuery provides a seamless, easy and efficent way to add or remove","og_url":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_author":"https:\/\/www.facebook.com\/fabiocimo","article_published_time":"2015-09-21T09:15:36+00:00","article_modified_time":"2017-12-21T14:14:09+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg","type":"image\/jpeg"}],"author":"Fabio Cimo","twitter_card":"summary_large_image","twitter_creator":"@fabiocimo","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Fabio Cimo","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/"},"author":{"name":"Fabio Cimo","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/1dfb88b4a8d08c37a6080311fd330a22"},"headline":"jQuery Add\/Remove Class Example","datePublished":"2015-09-21T09:15:36+00:00","dateModified":"2017-12-21T14:14:09+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/"},"wordCount":631,"commentCount":1,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg","articleSection":["jQuery"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/","url":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/","name":"jQuery Add\/Remove Class Example - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg","datePublished":"2015-09-21T09:15:36+00:00","dateModified":"2017-12-21T14:14:09+00:00","description":"In this example, we'll go through jQuery .addClass() and .removeClass() methods. jQuery provides a seamless, easy and efficent way to add or remove","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/jquery-add-remove-class-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/"},{"@type":"ListItem","position":3,"name":"jQuery","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/jquery\/"},{"@type":"ListItem","position":4,"name":"jQuery Add\/Remove Class Example"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/1dfb88b4a8d08c37a6080311fd330a22","name":"Fabio Cimo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b3df055f2e1b62e238889fafbb16121c68aab1adcd11af670e185cafae201b3b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b3df055f2e1b62e238889fafbb16121c68aab1adcd11af670e185cafae201b3b?s=96&d=mm&r=g","caption":"Fabio Cimo"},"description":"Fabio is a passionate student in web tehnologies including front-end (HTML\/CSS) and web design. He likes exploring as much as possible about the world wide web and how it can be more productive for us all. Currently he studies Computer Engineering, at the same time he works as a freelancer on both web programming and graphic design.","sameAs":["https:\/\/www.facebook.com\/fabiocimo","https:\/\/al.linkedin.com\/in\/fabiocimo","https:\/\/x.com\/fabiocimo","https:\/\/www.youtube.com\/fabiocimo1"],"url":"https:\/\/www.webcodegeeks.com\/author\/fabio-cimo\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/7081","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/75"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=7081"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/7081\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/919"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=7081"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=7081"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=7081"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}