I have a simple script (below) that on click (to the element with an id of #addClass) adds a class (.switcher) to the body tag. The script uses jquery.
I would like to know if it's possible to modify this script so that when the user moves on to the next page within the site the added class remains in place? In fact the class needs to stay in place until the element with an id #removeClass has been clicked no matter how many pages the user chooses to browse through. Please be gentle with your responses - I'm not much of a coder! If it's not possible with this script (or indeed with JS) does anyone have any suggestions as to how it may be possible

<script type="text/javascript">
    $("#addClass").click(function () {
    $("#removeClass").click(function () {



4 Years
Discussion Span
Last Post by Surfsup


Are these pages hard-coded HTML or dynamically built with server-side scripting?

If the latter, then what?



It's Wordpress site. The header file is sitewide so won't change throughout the site.
Does this help?


Mmm, the solution lies in saving the switcher false|true state somewhere. There are three basis choices; cookie, PHP $_session var, database. Each has its own scope.

Trouble is, WordPress has its own way of doing just about everything. I would suggest cookie but, due to cookie constraints, that may cut across WordPress's standard use of cookies. You really need a WordPress expert or to get lucky with a search in the WordPress documentation/forums.

(Before someone mentions it, a fourth option is to send the "switcher=0|1" on the url querystring merry-go-round but that would need to involve every internal url in the whole site so don't even think about it unless WP makes specific provision for such).

Sorry, it's not a gentle answer and sorry I can't help further.



Thanks - it sound as though it may be possible - which is a great start! Would you mind posting an code example using of one of the methods you suggest and I'll give it a whirl?


Ok - so it sounds as though it is possible - however I have little/no chance of solving this without assistance. Can I get any help with this - pretty please... ?

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.