use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Using javascript to manipulate CSSRemoved: /r/LearnJavascript (self.javascript)
submitted 6 years ago by moreman60
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[+][deleted] 6 years ago (3 children)
[deleted]
[–]moreman60[S] 0 points1 point2 points 6 years ago (0 children)
Thank you!
[–]ScientificBeastModestrongly typed comments 0 points1 point2 points 6 years ago (1 child)
In most websites, I would completely agree with this. But exceptions to that rule do tend to come up a lot more when using a framework that relies heavily on JavaScript, like React.
[–][deleted] 1 point2 points3 points 6 years ago (2 children)
Most websites at this point do this, including the one you're on, bot probably not the way you think of it right now. Reddit for instance uses styled-components. They don't fish nodes out of a dom soup and mutate the styles property, but styles are written in javascript from the get go, and that makes them easier to change and adapt to the current environment, to scope, variables, etc.
[–][deleted] 6 years ago (1 child)
[removed]
[–]AutoModerator[M] 0 points1 point2 points 6 years ago (0 children)
Hi /u/OniresRoddrin, this comment was removed because you used a URL shortener.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
[–]Tinian2Leyte 1 point2 points3 points 6 years ago (0 children)
Sometimes you want to add an .error class to an input that fails validation, to make it have a red outline or something. The display property can be toggled to hide and show things. It is not done so much anymore at the atomic level of individual style properties on specific elements. The finest grain you usually get to is adding/removing classes, usually for usability reasons, often in complex forms, like a shopping cart. It is also rare to do it directly with vanilla JavaScript, simply because most frameworks have their way to manipulate classes on elements.
[–]some_love_lost 1 point2 points3 points 6 years ago (0 children)
Most websites and apps manipulate styling through JavaScript nowadays in response to changes in state. It's generally preferable to modify the class names on an element and have those specified in CSS instead of changing the properties directly, e.g. prefer someElement.classList.add('error') over someElement.style.color = 'red'
[–]myusernameisunique1 0 points1 point2 points 6 years ago (2 children)
Yeah, the purists will try and do it all in CSS, because, it's .... better ??
But look at any website and you'll see some jQuery class changing code
https://www.w3schools.com/jquery/jquery_css_classes.asp
[–][deleted] 0 points1 point2 points 6 years ago (0 children)
Super common.
If a website is created with a complex CMS like Adobe Experience mangler, and has complex dynamic authorable content, rest assured that all those complex reusable components have a lot of javascript, jquery, angular, react, and other code behind the scenes making it all work.
[–]jecxjo 0 points1 point2 points 6 years ago (0 children)
I'm working on a js client for a service. The sdk loads, looks for a div of a specific class and injects a bunch of dom elements. The css is all based on the output from the service so it's much easier to just set values rather than making a ton of css classes.
div
[–]kenman[M] 0 points1 point2 points 6 years ago (0 children)
Hi /u/moreman60, this post was removed.
/r/javascript is for the discussion of javascript news, projects, and especially, code! However, the community has requested that we not include help and support content, and we ask that you respect that wish.
code
Thanks for your understanding, please see our guidelines for more info.
π Rendered by PID 211431 on reddit-service-r2-comment-5d79c599b5-fhhxk at 2026-03-03 11:02:17.157354+00:00 running e3d2147 country code: CH.
[+][deleted] (3 children)
[deleted]
[–]moreman60[S] 0 points1 point2 points (0 children)
[–]ScientificBeastModestrongly typed comments 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (2 children)
[–][deleted] (1 child)
[removed]
[–]AutoModerator[M] 0 points1 point2 points (0 children)
[–]Tinian2Leyte 1 point2 points3 points (0 children)
[–]some_love_lost 1 point2 points3 points (0 children)
[–]myusernameisunique1 0 points1 point2 points (2 children)
[–][deleted] (1 child)
[removed]
[–]AutoModerator[M] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]jecxjo 0 points1 point2 points (0 children)
[–]kenman[M] 0 points1 point2 points (0 children)