HTML and CSS Reference
In-Depth Information
<script src="myscript.js"></script>
Then you need a file called myscript.js containing this line of code:
window.alert('Linked script!');
Inline event handlers
The final way to include JavaScript in a page is through an inline event
handler. Events are things that can happen in a page, such as a user
clicking a button. You'll learn more about them in the section “Events”;
for now, you just need to know that you can create a handler for a click
event by adding an onclick attribute to an element. This is what the
page looks like.
When you click the button, the alert pops up. Here's the code:
<!DOCTYPE html>
<title>Inline event handler</title>
<button onclick="window.alert('Inline event!');">
Click me
You should notice two things about this code. First, no <script> ele-
ments were required: the JavaScript is directly in the markup. Second,
Search WWH ::

Custom Search