Any time
Open links in new tab
- 123
In HTML, the <script> tag is essential for incorporating JavaScript to make web pages interactive and dynamic. The tag can contain JavaScript code directly or link to an external JavaScript file using the src attribute. Common applications include image manipulation, form validation, and content alteration.
Example of Inline JavaScript in HTML
Here's a simple example of how to use JavaScript within an HTML document to change the content of an element with a specific ID:
<!DOCTYPE html><html><body><h2>My First JavaScript</h2><button type="button" onclick="displayDate()">Click me to display Date and Time.</button><p id="demo"></p><script>function displayDate() {document.getElementById("demo").innerHTML = Date();}</script></body></html>External JavaScript File
Alternatively, you can link to an external JavaScript file, which helps keep your HTML and JavaScript code separate:
HTML CSS JavaScript - Free Online Editors and Tools
TRENDING CONTENT
- Some results have been removed