Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics Hello, JavaScript! Add JavaScript to HTML

Why Is javascript always linked to HTML and CSS And not Java Or C++?

Why Is javascript always linked to HTML and CSS And not Java Or C++?

1 Answer

To make a simple website, you just need a HTML document. To make it pretty, you add a CSS file. To add interactivity you add JavaScript, which allows you to edit the DOM. DOM is kind of like a copy of the HTML that the browser makes and shows you on the screen. So when you visit websites, you're not seeing the actual HTML but the DOM.

The browser is a really powerful program that takes a bunch of code (HTML, CSS, JS) and renders all the colors and text and animations on your screen based on that code.

Java and other languages were not built to add interactivity to websites and the browsers wouldn't understand if you'd try to add a myScript.java file. But they do understand JavaScript code. So the browser knows how to change the DOM as all the instructions are written in the JS file. E.g. when a user clicks a button - which is a HTML element - the browser opens up a modal or whatever is specified in the JS file.

And even then, if you use some really new language features, they might still not work in some browsers - as the browsers haven't implemented these features yet.