Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
I never thought of taking the element and storing it in local storage, pretty sure you can't do that ... well and use it. I find that idea fairly amusing.
For the record folks on this site sometimes don't respond well to technical how tos / troubleshooting. Just one of those things. -
No, you can only store strings there, and why do you need to store DOM object there, you're doing something wrong.
-
10Dev28544yLocal storage can only store strings, so storing a DOM element would cause it to lose any attributes it had. This is also super bad practice, try storing the ID of the element, that way you can access the element by pulling the ID from localStorage, selecting by getElementById(), and then calling click
-
@nine Store that button ID, which will be a string, also, if you don't want to permanently store it, you can store it in window.name variable, it persists on reload.
-
Voxera113974yBut what do you mean by active?
A button has no active state as such unless you have built it.
So what your trying to do is just going to click the button on every reload.
Even if it works I would say its an antipattern.
You should instead have an onload that directly sets any state the button sets.
Because even if you right now have not on click action except setting the state its quite possible some one later adds one not expecting it to be triggered over and over. -
In jquery you can just do $(‘#buttonid’).click()
Didn’t know there was something called local storage in js -
pankaj21104yI have 14gb large zip file. Want to post these data using spring rest template.
Am getting out of memory exception when file size is more than 2 gb.
Any lead much appreciated. -
@c3r38r170 nope I never use it lol I use this thing called session or a database lol
-
asgs112794y@pankaj211 nice that you want to hijack a post with a random question
Don't read such a file in one go. Stream the data within acceptable limits -
@MadMadMadMrMim Different tools for different tasks. Using some more HTTP requests is overkill for some simple configurations.
-
@MadMadMadMrMim And I was talking about the jQuery tho'... You not only didn't answer the question correctly, but used jQuery for something that doesn't need it.
-
@c3r38r170 eh i used jquery in a way that someone would use jquery who uses jquery :P ok though document.getElementById("myid").click() :P
-
so simple and up front in the localstorage docs it is storing key'd data like a dictionary... kind of like a session, if you retrieve data from there its not likely getting parsed into an object, most especially a dom one however let me try something
document.getElementById('comment')
ouput: <textarea type="text" class="comment-text-input" placeholder="Add your 2 cents..." name="comment" id="comment"></textarea>
localStorage.setItem('test',document.getElementById('comment'))
localStorage.getItem('test')
output: "[object HTMLTextAreaElement]"
nope doesnt work because its not doing a JSON stringify and then a parse, its just dumping a toString()
better luck next time
use the developer console. -
@c3r38r170 wheres my plus one then :P I need the reinforcing giddiness that comes from an entirely artificial system of reward which represents the esteem of my peers goddamn it !!! FEED MY DAMN NEEDS ! LOL
-
@c3r38r170 you did get the joke right ? :P kind of a rip on all social media really lol its what we replaced actual social interaction with since the unwashed masses are now all braindead robots that dont know how to have fun of any kind anymore and think everything represents something else apparently which is half the reason i keep blocking this dumb crap out
Related Rants
I have a button using
localStorage.setItem(‘button’, getElementById(‘buttonId’))
And use it on page reload for clicking the button on page reload
localStorage.getItem(‘button’).click()
What’s wrong here?
question
button
js
reload