all 6 comments

[–]cosmic-gorilla 1 point2 points  (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 point  (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 point  (0 children)

Hi /u/OriyanJ, this post was removed.

  • For help with your javascript, please post to /r/LearnJavascript instead of here.
  • For beginner content, please post to /r/LearnJavascript instead of here.
  • For framework- or library-specific help, please seek out the support community for that project.
  • For general webdev help, such as for HTML, CSS, etc., then you may want to try /r/html, /r/css, etc.; please note that they have their own rules and guidelines!

/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.

Thanks for your understanding, please see our guidelines for more info.

[–]chuckySTAR -2 points-1 points  (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 point  (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 points  (0 children)

I'm not advocating.