Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Javascript Ternary operator | Light/Dark Theme

<label for="theme">Select theme: </label>
<select id="theme">
  <option value="white">White</option>
  <option value="black">Black</option>
</select>

<h1>This is my website</h1>

##################################

const select = document.querySelector('select');
const html = document.querySelector('html');
document.body.style.padding = '10px';

function update(bgColor, textColor) {
  html.style.backgroundColor = bgColor;
  html.style.color = textColor;
}

select.addEventListener('change', () => ( select.value === 'black' ) ? update('black','white') : update('white','black'));
Comment

PREVIOUS NEXT
Code Example
Javascript :: remove json parameter 
Javascript :: parse youtu.be url and get time 
Javascript :: make a table of data from db in jsp 
Javascript :: array.includes is not a function react 
Javascript :: how to use bootstrap in reactjs 
Javascript :: scriptcase javascript close modal form 
Javascript :: exit from jshell 
Javascript :: shorten req.body. function 
Javascript :: Return Early Pattern for Functions 
Javascript :: 00979fb28f7cc517ff28c035bb8ef10698d0d991304e9901ba214ad0cada69ef:script- 
Javascript :: get decimal on number javscri 
Javascript :: Fix the transition judder at 0/60 seconds javascript30 js clock 
Javascript :: js hit asp button onclick event 
Javascript :: How can I use a regex variable in a query for MongoDB 
Javascript :: jsx expressions 
Javascript :: delete nth node from end 
Javascript :: how to difference of arrey object 
Javascript :: how to create dynamic radio button in jquery 
Javascript :: es6 spread operator 
Javascript :: react using set Interval date time 
Javascript :: Combine multiple JSONs Into One 
Javascript :: _.extend Example 
Javascript :: using condition how to disable radio button in angular 
Javascript :: asp.net updatepanel autoscroll fix 
Javascript :: hoe to find items in mongoose 
Javascript :: javascript get minutes between two dates 
Javascript :: how to confirm if angular js in installed 
Javascript :: execute only once on multiple clicks javascript 
Javascript :: upload file to api angular 
Javascript :: click page object 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =