HTML or JavaScript, what should I write my Markup with?

twitter logo ・1 min read

Let us say that my website have a lot of things shown when i press button, which better:
1- having the Markup in the HTML file and use display {none, block, etc}
2- write the Markup using JavaScript with the function createElement

and why?
Thank you all !

twitter logo DISCUSS (6)
markdown guide


It's also going to be faster because the client already has the content in the page, you just need to flip the visibility with JS. You can also rely on the HTTP cache.

Unless we're talking about thousands or millions of rows in a table for example, that's probably something you want to have JS handle for you on demand.


Yeah this is what i thought about HTML it would be faster, but what make me ask this question is maybe in the future when the website start to be wide, it will be more easy to change the element by the unauthorized developer, which it's something I don't know if it good or not. Sometimes you don't want the element render only if he do what you want do, not after, not before, in that case you're forced to use the DOM
Hope I explain my point !


Sorry, I'm not sure I understood. Are you worried about security? The website runs on the user's computer and as long as you do the usual things server side to mitigate possible security flaws and don't store any sensible information on the local storage you shouldn't have any problems.

What sort of website will you build?

Yeah,I'm worried about the security, but yeah I know everything is done locally, so that mean I'm not worried about the data and these thing, what I'm worried about exactly is the people whom always trying to find a bug in your website, and sometimes there is a way of taken benefits of the Markup, if you didn't manage it well!

Social media website, what I'm talking about


I'd go for option one. It's less work and in my opinion more readable for future you.


Good point, maybe as you said the HTML saved the patterns of your design for the future

Classic DEV Post from Apr 18

The Weird Rules I Set Myself That Got Me a Job

Ahmad Tariq Alflahat profile image
Engineer of software, give it 100 of times when I try 💻

Sore eyes? now has dark mode.

Go to the "misc" section of your settings and select night theme ❤️