On a button click I have following code inside my .Post():
if (Comment != null && Grade > 0) {
$("navigation").attr('a[data-id="' + QuestionID + '"]')
.css({ "background-color": "green" });
} else if (Comment == null && Grade == null) {
$('a[data-id="' + QuestionID + '"]').css({ "background-color": "#D8D8D8" });
If I close my webapplication or just refresh it the color is gone. How can I make the color stay forever even if i close or refresh Do I have to addclass or something?
Okay, so short answer: you can’t.
Long answer: CSS files are stored on the remote server and served as requested (via the
<link />tag in the head of your HTML document). JavaScript is executed on your local machine, in the browser (unless you’re running node.js, I suppose). So your changes only exist as long as that particular scripting instance/page view is running. Reloading the page re-requests (depending on cache settings) the CSS file and reloads it.So, unless you want users to be able to freely modify your server files (a monumentally-bad idea), you really can’t do what it seems you want to…
HTH.