Inline JavaScript

Inline JavaScript is JavaScript that has been typed directly into the HTML tags of a Web page. This method is again simple, but what it gains in simplicity it lacks in power. Inline JavaScript is best suited to simple examples, and any complex JavaScript is best left to one of the other methods.

Here is an example of an inline JavaScript that brings up a prompt box:

<html>
<head>
<title>A Simple Page</title>
<script language="JavaScript">
<!-- Cloaking device on!

// Cloaking device off -->
</script>
</head>
<body>
<p onclick="prompt('How many do you want', 'Enter quantity');"> Click here to specify 
quantity</p> </body> </html> ...

Get JavaScript™ 1.5 by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.