{"id":630,"date":"2012-08-21T11:08:27","date_gmt":"2012-08-21T11:08:27","guid":{"rendered":"http:\/\/codeatelier.wordpress.com\/?p=227"},"modified":"2016-09-10T14:55:46","modified_gmt":"2016-09-10T14:55:46","slug":"how-jquery-toggle-class-works","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/how-jquery-toggle-class-works\/","title":{"rendered":"How Jquery Toggle Class Works"},"content":{"rendered":"<p><strong>Toggle Class does not work by the way you think<\/strong><\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n.ClassA\r\n{        \r\n  color : green;\r\n}\r\n\r\n.ClassB\r\n{\r\n  color : red;\r\n}\r\n<\/pre>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n $('document').ready(function(){\r\n   $('.ClassA').on('click', function(){\r\n      alert($(this).attr('class'));\r\n      $(this).toggleClass('ClassB')\r\n   }); \r\n });\r\n<\/pre>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\n&lt;div&gt;Class A&lt;\/div&gt;\r\n&lt;div&gt;Class B&lt;\/div&gt;\r\n<\/pre>\n<p>After the first Time ClassA is Applied When you click ClassA both ClassA and ClassB will be applied to the same tag.<\/p>\n<p>The alert message will display output some thing link ClassA ClassB<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Toggle Class does not work by the way you think .ClassA { color : green; } .ClassB { color : red; } $(&#8216;document&#8217;).ready(function(){ $(&#8216;.ClassA&#8217;).on(&#8216;click&#8217;, function(){ alert($(this).attr(&#8216;class&#8217;)); $(this).toggleClass(&#8216;ClassB&#8217;) }); }); &lt;div&gt;Class A&lt;\/div&gt; &lt;div&gt;Class B&lt;\/div&gt; After the first Time ClassA is Applied When you click ClassA both ClassA and ClassB will be applied to the same tag.&hellip; <a href=\"https:\/\/codethataint.com\/blog\/how-jquery-toggle-class-works\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-630","post","type-post","status-publish","format-standard","hentry","category-jquery"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/630","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=630"}],"version-history":[{"count":2,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/630\/revisions"}],"predecessor-version":[{"id":1599,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/630\/revisions\/1599"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=630"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=630"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=630"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}