Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » How do I create a new element with a class with JS
- god286
- Scratcher
1000+ posts
How do I create a new element with a class with JS
You should learn it, it will help you in the future. I have no idea on how localstorage works
Basically you can store key-value pairs. The value has to be a string though.
Here are some of my followers!
I joined: 5 years, 9 months, 24 days ago (31/03/2018)
I have: 479 followers
In total, I have attained: 1,403 loves, 1,145 favourites, and 33,731 views.
Fun Fact: If my account continued to gain followers at a similar rate to right now, in 14,210 years I would reach the number of followers griffpatch has today! Try to imagine how many followers he would have then!
Thank you everyone!
Script created by god286.
- MagicCrayon9342
- Scratcher
1000+ posts
How do I create a new element with a class with JS
well considering what your telling me doesn't help at all I'll just have to go without the feature until I figure it out in like 20 years.You should learn it, it will help you in the future. I have no idea on how localstorage works
Basically you can store key-value pairs. The value has to be a string though.
Actual code goes way farther and makes the flow of software creation much faster than links.
Last edited by MagicCrayon9342 (Jan. 16, 2022 01:03:08)
- CST1229
- Scratcher
1000+ posts
How do I create a new element with a class with JS
A quick guide: umm well I have no idea on how localstorage works and nothing on stack overflow works
// get local storage (you could use window.localStorage everytime but that's typing more characters) const storage = window.localStorage; // set values storage.setItem("key", "value"); // NOTE: values are automatically converted to strings, I think using x.toString(). // for objects, this returns "[object Object]" and for arrays, it's a comma-separated list of values // so you might want to JSON.stringify() the value before storing, then JSON.parse() it afterhand // get values storage.getItem("key") // -> value // console.log(storage.getItem("key")) // remove an item storage.removeItem("key"); // clear this site's localstorage storage.clear(); // there's also storage.length and storage.key(number)
Last edited by CST1229 (Jan. 16, 2022 03:19:39)
This is a signature. It's a piece of text that appears below every post I write. Click here to learn more, including how to make your own.
RIP assets image hosting. 2013?-2023
RIP assets image hosting. 2013?-2023
- MagicCrayon9342
- Scratcher
1000+ posts
How do I create a new element with a class with JS
ok, also does anyone know why stack overflow code never works?A quick guide: umm well I have no idea on how localstorage works and nothing on stack overflow works// get local storage (you could use window.localStorage everytime but that's typing more characters) const storage = window.localStorage; // set values storage.setItem("key", "value"); // NOTE: values are automatically converted to strings, I think using x.toString(). // for objects, this returns "[object Object]" and for arrays, it's a comma-separated list of values // so you might want to JSON.stringify() the value before storing, then JSON.parse() it afterhand // get values storage.getItem("key") // -> value // console.log(storage.getItem("key")) // remove an item storage.removeItem("key"); // clear this site's localstorage storage.clear(); // there's also storage.length and storage.key(number)
- CST1229
- Scratcher
1000+ posts
How do I create a new element with a class with JS
I think you should store the cards in something like an array or an object then recreate them when loading but if you really want to store the DOM, you can get/set the innerHTML of the cards container and store that in localstorage. Can I save the DOM to localStorage as a string then every time the app is loaded it loads the DOM back in to the page.
Last edited by CST1229 (Jan. 16, 2022 04:07:04)
This is a signature. It's a piece of text that appears below every post I write. Click here to learn more, including how to make your own.
RIP assets image hosting. 2013?-2023
RIP assets image hosting. 2013?-2023
- NFlex23
- Scratcher
1000+ posts
How do I create a new element with a class with JS
(#26)Which “stack overflow code” doesn't work?ok, also does anyone know why stack overflow code never works?A quick guide: umm well I have no idea on how localstorage works and nothing on stack overflow works// get local storage (you could use window.localStorage everytime but that's typing more characters) const storage = window.localStorage; // set values storage.setItem("key", "value"); // NOTE: values are automatically converted to strings, I think using x.toString(). // for objects, this returns "[object Object]" and for arrays, it's a comma-separated list of values // so you might want to JSON.stringify() the value before storing, then JSON.parse() it afterhand // get values storage.getItem("key") // -> value // console.log(storage.getItem("key")) // remove an item storage.removeItem("key"); // clear this site's localstorage storage.clear(); // there's also storage.length and storage.key(number)
Here are some SO links that work and should answer your questions:
Last edited by NFlex23 (Jan. 16, 2022 11:50:58)
Help improve the Advanced Topics (Really!)
Before you create a topic:
Always search for duplicates or other similar topics before making an umbrella topic, e.g., “The Mac Topic”.
- Is it about something you are planning on making but haven't made yet? If so, please wait to post until you have created a working prototype. This is a key factor to keeping the ATs as clean as possible.
- The ATs aren't technical support. It is perfectly valid to ask questions about things related to programming, but not issues with external websites, apps, or devices. Most sites have their own support system; try asking there!
- Is it related to something you are making in Scratch? (This includes OSes and other Scratch projects) If so, please post in Collaboration, Show and Tell, or another similar forum.
- Is your topic questionably “advanced”? Try browsing the other forums to see if your topic fits better in one of those.
- Issues with Scratch itself should be put in Bugs and Glitches.
- Maximouse
- Scratcher
1000+ posts
How do I create a new element with a class with JS
It almost always works if you change things like variable names to match your existing code. ok, also does anyone know why stack overflow code never works?
- MagicCrayon9342
- Scratcher
1000+ posts
How do I create a new element with a class with JS
(#30)most of the time the existing code is from stack overflowIt almost always works if you change things like variable names to match your existing code. ok, also does anyone know why stack overflow code never works?
- god286
- Scratcher
1000+ posts
How do I create a new element with a class with JS
stackoverflow isnt a person its a community most of the time the existing code is from stack overflow
Here are some of my followers!
I joined: 5 years, 9 months, 24 days ago (31/03/2018)
I have: 479 followers
In total, I have attained: 1,403 loves, 1,145 favourites, and 33,731 views.
Fun Fact: If my account continued to gain followers at a similar rate to right now, in 14,210 years I would reach the number of followers griffpatch has today! Try to imagine how many followers he would have then!
Thank you everyone!
Script created by god286.
- Discussion Forums
- » Advanced Topics
- » How do I create a new element with a class with JS