3

Got a question for any web devs on here.

How would you feel about making elements in JavaScript (if you have some divs that are exactly the same) rather than having all of them in the HTML source file?

Comments
  • 3
    You mean creating the html with js dom instead of vanilla syntax? Usually I only render a “repetitive” elements or if it’s controlled through ajax
  • 2
    @devTea Yeah, that's exactly what I meant. I was slightly preoccupied when I posted.

    Basically right now on a little thing I'm working on, I have 5 divs in a row. They all have the same elements in them, and I just wanted some opinions on using JS DOM to create the elements
  • 3
    @M1sf3t Nah, it's more of "I don't want these ~75 lines in the HTML file when I can have like 15 in the JavaScript that creates those 75"

    But I'm just asking for opinions right now
  • 3
    @infernalempress if it can be dynamicaly programmed by js then go for it, that’s the use of it isn’t it?
  • 2
    @devTea You have a very good point. I think what I'll do is write it, then see if it makes any difference at all on load times or anything. It'll have to be tomorrow tho. I have to meet with my "study buddy" today cause we're both on the verge of not graduating.
  • 1
    @infernalempress
    have them once as a template and make the others by copying and manipulating
  • 2
    @infernalempress speed isn’t going to be a problem, backward compatibility is if you’re using a newer syntax, you could use old js syntax for looping simple html
  • 0
    @infernalempress sounds like you need vue
  • 0
    Maybe I completely misunderstood the subject, but if it's what I'm thinking, there's a very good course on Pluralsight about creating kind of a framework using js classes to render the html (extending the html element)
Add Comment