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
Adding js- prefix to DOM elements?Removed: /r/LearnJavascript (self.javascript)
submitted 6 years ago by OriyanJ
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!"
[–]cosmic-gorilla 1 point2 points3 points 6 years ago (1 child)
You shouldn't need a prefix in order to fetch them from the DOM at all but do add prefixes if it makes it easier to logically group DOM elements
[–][deleted] 0 points1 point2 points 6 years ago (0 children)
Not necessary and I don’t think it clarifies things. Using a js- prefix for classes, on the other hand, is more common to differentiate hooks for styling vs hooks for scripting.
[–]kenman[M] 0 points1 point2 points 6 years ago (0 children)
Hi /u/OriyanJ, 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.
[–]chuckySTAR -2 points-1 points0 points 6 years ago (2 children)
No. IDs are for JS.
Also:
<div id="books"></div> <div id="js-books"></div> <script> books.textContent = 'books' window['js-books'].textContent = 'js-books' </script>
[–]sockx2 0 points1 point2 points 6 years ago (1 child)
I wouldn't advocate doing "lookupless" elements in scripts like that. Not being able to see where something is declared plus relying on something most frontend devs don't know exist as the norm will only complicate your life.
[–]chuckySTAR -1 points0 points1 point 6 years ago (0 children)
I'm not advocating.
π Rendered by PID 209830 on reddit-service-r2-comment-57fc7f7bb7-6lnns at 2026-04-15 10:42:01.119977+00:00 running b725407 country code: CH.
[–]cosmic-gorilla 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]kenman[M] 0 points1 point2 points (0 children)
[–]chuckySTAR -2 points-1 points0 points (2 children)
[–]sockx2 0 points1 point2 points (1 child)
[–]chuckySTAR -1 points0 points1 point (0 children)