Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

226
Views
How would I use localStorage to remember button click in PugJS?

This is what I have in my .pug file that I need the website to remember. If a user clicks the Large button then the website should remember that when the website is refreshed.

.scaling
        scalingButton(onclick='body.style.fontSize = "1.0em"')='Normal' 
        scalingButton(onclick='body.style.fontSize = "1.2em"')='Medium'
        scalingButton(onclick='body.style.fontSize = "1.5em"')='Large'

and here is what I have in the .css file for these buttons:

.scaling{
    text-align: end;
    position: fixed;
    margin: 150px;
    margin-right: 0%;
    margin-bottom: 5%;
    bottom: 0px;
    right :20%;
}

scalingButton{ 
    background-color: white;
    padding: 5px 10px;
    
    margin-top: 600px;
    font-weight: bold;
    border-radius: 3px;
    border: 2px solid black;
    filter: drop-shadow(2px 2px 2px black);
    transition: 0.3s;
  }
  
  scalingButton:hover{
    background-color: grey;
    cursor: pointer;
  }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to write a function that stores value in localStorage and when page is loaded (DOMContentLoaded ) you need to check localStorage, if localStorage has a font-size then you can apply it to the body.

script:

function changeFontSize(size) {
    let fontSize = size + "em"
    body.style.fontSize = fontSize;
    localStorage.setItem('font-size', fontSize);
} 

document.addEventListener("DOMContentLoaded", function(event) {
    let fontSize = localStorage.getItem('font-size');

    if(fontSize) {
         body.style.fontSize = fontSize;
    }
});

template

.scaling
    scalingButton(onclick="changeFontSize('1.0em')")='Normal' 
    scalingButton(onclick="changeFontSize('1.2em')")='Medium'
    scalingButton(onclick="changeFontSize('1.5em')")='Large'
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!