jquery - Removing class from variable on .click -


I searched for it and in all sincerity I think the answer is probably for me, but I'm a bit too I'm not going to work for it.

If you can help that would be awesome.

Actually I've got a set of buttons that dynamically adds a class to a text field from a CMS and hide it on the request.

The code works, but I wonder if somebody put me in the hand and said holding it because the weight of repetition is the main thing I wanted to do. AddClass and .removeClass or even Did that .toggleClass apply? Instead of repeating the function on the variable, but every time I can tell the var will remove the object from the head.

Anyway, any help is greatly appreciated.

& lt; Button class = 'settings' title = "settings" & gt; Sparrow setting & lt; / Button & gt; & Lt; Button class = "employee" title = "employee" & gt; STAFF & lt; / Button & gt; & Lt; Button class = "building" title = "employee" & gt; Building & lt; / Button & gt; & Lt; Button class = 'services' title = "settings" & gt; Services & lt; / Button & gt; & Lt; Button class = "partner" title = "staff" & gt; Partners & lt; / Button & gt; & Lt; Button class = "network" title = "employee" & gt; Network & lt; / Button & gt; & Lt; Div class = "settings_init" & gt; & Lt ;? Php perch_content ('childcare_text'); ? & Gt; & Lt; / Div & gt; & Lt; Div class = "settings_text test" & gt; & Lt ;? Php perch_content ('childcare_text'); ? & Gt; & Lt; / Div & gt; & Lt; Div class = "staff_text test" & gt; & Lt ;? Php perch_content ('staff_text'); ? & Gt; & Lt; / Div & gt; & Lt; Div class = "buildings_text test" & gt; & Lt ;? Php perch_content ('buildings_text'); ? & Gt; & Lt; / Div & gt; & Lt; Div class = "services_text test" & gt; & Lt ;? Php perch_content ('services_text'); ? & Gt; & Lt; / Div & gt; & Lt; Div class = "partners_text test" & gt; & Lt ;? Php perch_content ('partners_text'); ? & Gt; & Lt; / Div & gt; & Lt; Div class = "network_text test" & gt; & Lt ;? Php perch_content ('network_text'); ? & Gt; & Lt; / Div & gt; $ (document) .ready (function () {text = $ ('staff_text, .buildings_text, .settings_text, services_text, partners_text, $ ('. Settings ') (function () {$ ('. Settings_text '); button = $ (' staff. Creation, .settings, .services, .partners, .network) .addClass ("toggle"); $ ('Staff_text, .buildings_text, .services_text, .partners_text, .network_text'). RemoveClass ("Toggle");}); $ ('Staff.) Click (function ($ ('. Toggle '); $ ( 'Buildings_text, .settings_text, .services_text, .partners_text, .network_text'). RemoveClass ("toggle");}); $ ('AddClass' ("toggle"); $ (' staff_text, .settings_text, .services_text , .partners_text, .network_text '). Click RemoveClass ("Toggle" (". Service") AddClass ("toggle"); $ ('. Staff_text, .buildings_text, .settings_text, .partners_text, .network_text'). RemoveClass ("Toggle");}) ; $ ('Partner.text') (function () {$ ('partners.text'). AddClass ("toggle"); $ ('staff_text, .buildings_text, .settings_text, .services_text, .network_text') RemoveClass ("Toggle");}); $ ('Network') Click (function () ($ ('. Network_text'). AddClass ("Toggle"); $ ('Staff_text, .buildings_text, .settings_text, .services_text, .partners_text'). RemoveClass ("Toggle");}); button. Click (function () {$ ('settings_init'). AddClass ('test');}); });

or this:

HTML:

  & lt; Button class = "settings" name = "button" title = "settings" & gt; Sparrow setting & lt; / Button & gt; & Lt; Button class = "employee" name = "button" title = "employee" & gt; STAFF & lt; / Button & gt; & Lt; Button class = "building" name = "button" title = "employee" & gt; Building & lt; / Button & gt; & Lt; Button class = "services" name = "button" title = "settings" & gt; Services & lt; / Button & gt; & Lt; Button class = "affiliate" name = "button" title = "employee" & gt; Partner & lt; / Button & gt; & Lt; Button class = "network" name = "button" title = "employee" & gt; Network & lt; / Button & gt; & Lt; Div class = "settings_init" & gt; 1 & lt; / Div & gt; & Lt; Div class = "settings_text test divs" & gt; 2 & lt; / Div & gt; & Lt; Div class = "staff_text test divs" & gt; 3 & lt; / Div & gt; & Lt; Div class = "buildings_text test divs" & gt; 4 & lt; / Div & gt; & Lt; Div class = "services_text test divs" & gt; 5 & ​​lt; / Div & gt; & Lt; Div class = "partners_text test divs" & gt; 6 & lt; / Div & gt; & Lt; Div class = "network_text test divs" & gt; 7 & lt; / Div & gt;  

Javascript:

  $ (document) .ready (function () {$ ('[name = button]'). $ ('. Settings_init'). AddClass ('test'); $ ('divs'). Delete class (' toggle '); $ ('. '+ + ($) (This) .attr (' class') + ' _text '). AddClass (' Toggle ');});});  

Comments