Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a couple of ways. I'm going to do it using jQuery because I'm lazy :)</p> <pre><code>var divThatCanHaveItsAttributesChanged = $("#divThatCanHaveItsAttributesChanged"); $("a.linkThatCanBeClickedToChangeTheme").on('click', function () { var linkThatWasClicked = $(this); divThatCanHaveItsAttributesChanged.attr('data-theme', linkThatWasClicked.attr('data-theme')); }); </code></pre> <p>Pardon the super long variable names, but hopefully it's a bit clearer than just a/b/c.</p> <p>Edit: Alright, after our conversation, what you want is something more like the following:</p> <pre><code>var divThatCanHaveItsAttributesChanged = $("#divThatCanHaveItsAttributesChanged"); $("a.linkThatCanBeClickedToChangeTheme").on('click', function () { var linkThatWasClicked = $(this); var theme = linkThatWasClicked.attr('data-theme'); divThatCanHaveItsAttributesChanged.attr('data-theme', theme); eraseCookie('theme'); createCookie('theme', theme, 365); }); </code></pre> <p>Grab the code near the bottom of <a href="http://www.quirksmode.org/js/cookies.html" rel="nofollow">http://www.quirksmode.org/js/cookies.html</a> and use that as a starting point for setting and reading cookies. So, now that you've got a cookie with the name 'theme' set you have a few options. The preferred one I'm sure will be with having the backend language you are using read the cookie and alter the template you're using. For example with PHP:</p> <pre><code>$theme = empty($_COOKIE['theme']) ? 'default-theme' : $_COOKIE['theme']; </code></pre> <p>And then you could use that to put the 'theme' in the right spot. Alternatively if you don't have that kind of capability you could do it with javascript. </p> <pre><code>$.ready(function () { var theme = readCookie('theme'); //Either the cookie has expired or it doesn't exist if(!theme) {return;} $("#divThatCanHaveItsAttributesChanged").attr('data-theme', theme); }); </code></pre> <p>This might cause a flash though as the theme is changed. There are a huge number of ways of handling this, but at minimum you'll want to set that cookie or send the result to the server to attach to the person's account.. depending on complexity.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload