How to permanently change the color of some elements?

qadenza

I have a php page on which I want a user can change the color of some elements, and next time he load the page his choices should be loaded by default.

I'm using jQuery click() function to change the colors, and to save the changes on server side I suppose that the best way is using jquery/json, but I'm totally new about this.

Should I have a separate json file with color options stored? I found so many stories on web about jquery/json, but still need an example how to accomplish this task. Please help with a useful link or code example.

 #div01 {
        background:#008080;
        color:#ffffff;
    }


$('#btnBlue').click(function () {
    $('#div01').css('background', '#0000ff');
    $('#div01').css('color', '#ffffff');
});

$('#btnRed').click(function () {
    $('#div01').css('background', '#ff0000');
    $('#div01').css('color', '#0000ff');
});
federico-t

If you are looking for a concrete example on how to do this, this might do the trick. First, use this JavaScript library: https://github.com/carhartl/jquery-cookie.

Then, this would be your script:

var backgroundColor = $.cookie('backgroundColor'), color = $.cookie('color');
$('#div01').css('background', backgroundColor);
$('#div01').css('color', color);

$('#btnBlue').click(function () {
    $.cookie(backgroundColor, '#0000ff');
    $.cookie(color, '#ffffff');
    $('#div01').css('background', backgroundColor);
    $('#div01').css('color', color);
});

$('#btnRed').click(function () {
    $.cookie(backgroundColor, '#ff0000');
    $.cookie(color, '#0000ff');
    $('#div01').css('background', backgroundColor);
    $('#div01').css('color', color);
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to permanently change a specific bash shell color?

From Dev

How do I permanently change the background color of a row in a Listview?

From Dev

How to permanently change swappiness

From Dev

How to change the color of some colored pixels on a texture?

From Dev

How do I change the color of the MFMessageComposeViewController elements?

From Dev

How to change color of elements with angular.js

From Dev

how to change the text color when checking on elements

From Dev

How to change the color of Kendo Grid elements

From Dev

How to change the color of two elements using javascript?

From Dev

Change the terminal color profile and font size permanently

From Dev

How do I change the highlighter color in Adobe Acrobat Reader DC permanently?

From Dev

How to change umask mode permanently?

From Dev

How to change MTU setting permanently

From Dev

How to change umask mode permanently?

From Dev

How to permanently change floppy rights?

From Dev

How to change system timezone permanently?

From Dev

change number of elements color

From Dev

How to save some values permanently on a browser?

From Dev

How to set Powershell Color scheme permanently

From Dev

How to change text color in some headers in Expandable List

From Dev

How to bind onclick event to elements of a class permanently

From Java

How to randomly change the signs of some of the elements in a numpy array?

From Dev

How can I change the background color of elements when they're clicked?

From Dev

How can I change the background color of elements when they're clicked?

From Dev

How to Get Multiple elements to change color on hover CSS?

From Dev

How can I change default elements color android layout?

From Dev

change color some string of textview

From Dev

How can I permanently change the cursor for an NSButton?

From Dev

how to change DNS server permanently on Ubuntu 20.04?

Related Related

  1. 1

    How to permanently change a specific bash shell color?

  2. 2

    How do I permanently change the background color of a row in a Listview?

  3. 3

    How to permanently change swappiness

  4. 4

    How to change the color of some colored pixels on a texture?

  5. 5

    How do I change the color of the MFMessageComposeViewController elements?

  6. 6

    How to change color of elements with angular.js

  7. 7

    how to change the text color when checking on elements

  8. 8

    How to change the color of Kendo Grid elements

  9. 9

    How to change the color of two elements using javascript?

  10. 10

    Change the terminal color profile and font size permanently

  11. 11

    How do I change the highlighter color in Adobe Acrobat Reader DC permanently?

  12. 12

    How to change umask mode permanently?

  13. 13

    How to change MTU setting permanently

  14. 14

    How to change umask mode permanently?

  15. 15

    How to permanently change floppy rights?

  16. 16

    How to change system timezone permanently?

  17. 17

    change number of elements color

  18. 18

    How to save some values permanently on a browser?

  19. 19

    How to set Powershell Color scheme permanently

  20. 20

    How to change text color in some headers in Expandable List

  21. 21

    How to bind onclick event to elements of a class permanently

  22. 22

    How to randomly change the signs of some of the elements in a numpy array?

  23. 23

    How can I change the background color of elements when they're clicked?

  24. 24

    How can I change the background color of elements when they're clicked?

  25. 25

    How to Get Multiple elements to change color on hover CSS?

  26. 26

    How can I change default elements color android layout?

  27. 27

    change color some string of textview

  28. 28

    How can I permanently change the cursor for an NSButton?

  29. 29

    how to change DNS server permanently on Ubuntu 20.04?

HotTag

Archive