Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript and the DOM (Retiring) Making Changes to the DOM Creating New DOM Elements

Can you create a website in JS alone?

I have yet to finish this course but, in theory could you code in entire website in JS by adding HTML to the website through JavaScript?

2 Answers

Adam Duffield
Adam Duffield
30,493 Points

100% possible, JavaScript is very advanced nowadays.

If it's a pretty looking frontend site with very little functionality e.g. just text & images, maybe a modal & a mobile menu. You can easily build a site in just html, css & JS. If your website requires say for example a blog, or your developing an API for a website to collect data from you can use server side JavaScript such as Node.js to handle the "backend code" & yet still use Html, Css & JS to develop the frontend of a website.

JS is probably one of the most flexible languages. You can create websites, API's, Desktop Applications & Mobile Apps in JS.

UPDATE... I just re-read the question... You could build a fully fledged html site by passing the html in JavaScript files (I'm assuming you mean by creating elements & appending them). But i seriously would not recommend it, it would look very ugly, very quickly & be harder to manage because of it. Once you begin to play with JavaScript frameworks you will see that it can be handled in multiple different easier ways but generally, leave html to do the job of html.

Adam

Steven Parker
Steven Parker
210,425 Points

I assume you mean adding HTML to the page inside the browser. You nearly could, but it takes a little bit of HTML code to load in the JavaScript to begin with. But it would still be extremely labor-intensive compared to writing HTML directly.

You could, however, generate the HTML at the server end using JavaScript and the node.js engine. So in that sense, yes, you could have an entire site written in JS.