localstorage value is null

Complete javascript beginner here. I’m trying to make it so my text document saves its content in my textbox whenever I refresh the page, but for some reason whenever I try to see if the content’s been saved the value just comes back as null. Here’s my HTML div class="scratchpad" contenteditable="true" name="scratchpad" id="scratchpad"></div> and here’s… Read More localstorage value is null

How can I set a variable in JavaScript using attributes other than tag, class or ID name?

So my question is quite simple, see the code below. I would like to save the two spans in two different variables based on their value in the "data-language" attribute. Any idea how could I do this? <div class=”language-select”> <span class=”language-item” data-language=”hu”>HU </span> <span>/ </span> <span class=”language-item” data-language=”en”> EN</span> </div> >Solution : You can just… Read More How can I set a variable in JavaScript using attributes other than tag, class or ID name?

react – add to the same localStorage from two different components

I have two different components that show different categories of food and trying to implement a save button for both of them using localStorage. I have this code on both of them const [menu, setMenu] = useState([]); const AddtoMenu = (e,selectedItem) => { let newMenu; if (menu.includes(selectedItem)) { // If the item is already in… Read More react – add to the same localStorage from two different components

I save state in a Local storage, but modal appears on initial load for a <1 sec

I’ve got a simple cookie policy modal on initial load. I save state in a Local storage, everything works, but modal apperears for <1 second and dissappears. import React, { useState, useEffect } from "react"; import styled from "@emotion/styled"; const Cookies = () => { const [cookie, setCookie] = useState(false); useEffect(() => { const cookieAgrees… Read More I save state in a Local storage, but modal appears on initial load for a <1 sec

Cant get my create/login function to work! (localStorage) (preventDefault(); won´t work)

so i have a main HTML page with to additional HTML pages for creating a user an login (as a created user). Im using localStorage to store the users data and want the user to stay logged in (at the main page) until they are logged out (havent gotten to that part yet, idk what… Read More Cant get my create/login function to work! (localStorage) (preventDefault(); won´t work)

Saving information to localStorage, but localStorage is not saving it on refresh (React.js)

I’m creating this project, but I am having trouble learning why my code is not being saved to localStorage upon refresh. When I add stuff to the JSON file it saves properly, but when I reload all of the data from the JSON file disappears. I have tried many different formats for loading in the… Read More Saving information to localStorage, but localStorage is not saving it on refresh (React.js)

Checkbox state isn't applied correctly from the localStorage

I have a simple checkbox. I want to save the state that the user set (so if they checked the checkbox, it stays that way after the page reload, if they checked and unchecked it, it should stay unchecked after the page reload). <input type="checkbox" class="dm-btn" id="dmtoggle" style="display:none;"> <label for="dmtoggle"></label> $(".dm-btn").on("click", function(){ localStorage.setItem("dm-checkbox", $(".dm-btn").prop(‘checked’)); });… Read More Checkbox state isn't applied correctly from the localStorage