/    Sign up×
Community /Pin to ProfileBookmark

How to change the theme in javascript?

I am trying to add theme on my web pages on button click, but i am unable to do it.
Would you please tell me how to do it?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@rootNov 09.2016 — for example, in the head of your HTML
[code=html]<link type="text/css" rel="stylesheet" href="../base.css" id="the_theme" />[/code]
then with your button, add an onclick event handler to call a function
function changit(){
document.getElementById('the_theme').href = '../alternative.css';
}

That should allow you to change the theme, to give multiple choices, your options are to use a drop down menu that calls and changes when selected.
Copy linkTweet thisAlerts:
@Rihan_sharmaNov 21.2016 — You can set an Id to the link tag and switch the css at runtime.

HTML :-

<link type="text/css" rel="stylesheet" media="all" href="../green.css" id="theme_css" />

JS

document.getElementById('buttonID').onclick = function () {

document.getElementByI
Copy linkTweet thisAlerts:
@rootNov 21.2016 — You can set an Id to the link tag and switch the css at runtime.

HTML :-

<link type="text/css" rel="stylesheet" media="all" href="../green.css" id="theme_css" />

JS

document.getElementById('buttonID').onclick = function () {

document.getElementById('theme_css').href = '../red.css';

};

Corporate Gift Ideas | Customized Pen Drives[/QUOTE]


Why answer with the same answer as mine unless you are trying to bump your post count...

You should also read the webdeveloper site AUP about posting links in signatures advertising stuff... unless you have permission to post them, you should refrain from doing so.
×

Success!

Help @Vayamtech spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...