Change site color with jquery

Asked

Viewed 48 times

1

Is there any way to change the color of the entire site with jquery? type, I have a site that its default color is purple but only a few parts, and I wanted to change these parts according to the user’s choice, I wanted a way that js did not change the source code on the console...

Does anyone have any idea how to do that?

  • "i wanted a way that js did not change the source code on the console"... How so? Would prevent console changes?

  • With "CSS Variable" you achieved this in a very easy way. But your question is too wide is hard to answer so, Create an example with code and edit your question that is easier

  • @hugocsl Ample even, because if you give an F5 everything goes back to normal.

  • If you look at twitter, in the theme change part, it will change the color of the whole site, but if you look at the source code on the console, you will see that nothing is changed, it seems magic, but I did not find how

  • @dvd e ai vai cookie / localStorage etc... difficult to give a simple answer... Roberto, start with clearer and objective questions, as your project goes going you will ask again that the site is for this same.

  • Robert, but see that this is quite unnecessary whether you have the changes on the console or not. What matters is what the user sees on the screen

  • I found out how ... it is very complex msm, but as soon as I finish, I will post the code

  • Associated: https://answall.com/questions/286813/como-memoriza-uma-a%C3%A7%C3%A3o-em-um-site

Show 3 more comments

1 answer

1

About js not changing the source code on the console I can’t help you, but about changing the color with jquery just assign a class equal to all elements you want to change color and do this:

//class do botão que muda de cor
$('.btn-muda-cor').click( function(){
    //aqui eu pego o id, cada id vc pode colocar algo para identificar a cor 
    //que você deseja atribuir, ex: o id que eu peguei é igual a 1,então eu 
    //faço um if na hora de atribuir a cor que se id = 1 cor seja vermelha 
    //por exemplo.
    var id_campo = this.id;

    //chamo a função para atribuir a cor passando o id do campo
    atribuir_cor(id_campo);
});

function atribuir_cor(id){
    //comparo o id
    if(id == 1){
        //aí você coloca a class que quer que mude de cor
        $('.class').css('background', red);
        //o .css recebe 2 parâmeotros, o primeiro é o o nome da instrução do 
        //css e a segunda o valor que será atribuido a ele
    }
}

On give F5 and restart, you can save the color or save the variable as of session in php, so you keep the color when changing page, der F5 etc. Or if your site has registered clients, you can save a db, then when you log in the site goes to the color that he set earlier

  • Several elements with the same id?

  • @dvd with the msm class, I put msm id? If it was pardon, I mistook here kkkkkkkk

Browser other questions tagged

You are not signed in. Login or sign up in order to post.