JavaScript: Adding Interactivity#
For the final layer of our tutorial, see how JavaScript can bring our web pages to life!
While with HTML and CSS we can make a webpage colorful and informative, almost every modern site will require interactivity in some form, such as buttons, drop-down menus, and more. This is where JavaScript comes in, allowing us to make our site responsive to user events and to update information without needing to reload the site and edit the HTML code in real-time!
Common interactive features can be things as simple as a site responding to a click to more advanced forms like action prompts or real-time data representation.
In each of these examples, there is a certain situation, which triggers the reaction, called an event. JavaScript comes with dozens of common pre-built events that can be used to save time and make your work more interesting. These events can be linked to call functions, thus achieving interactivity.
Note: You can also use JavaScript frameworks and libraries to gain access to prewritten code for special functionalities.
Some common ones are AngularJS, NodeJS, and Django (written in Python).
To add JavaScript to an HTML file, we need to add the <script>
container to our HTML file. This is where JavaScript can be written. As the two are so closely entwined now, you don’t even need to download anything additional! The <script>
section is executed when the webpage is first loaded and will continue to check for the occurrence of an event, such as a click.
Note: Keep in mind that other programming languages, like PHP, Ruby on Rails, and Python, are also used for web development, especially for back-end and server-side software.
See our Web Development in Python article to learn more.