Javascript: <script> Tag

JavaScripts can manipulate images, validate forms and change the contents in your webpages to make them more dynamic and interactive. But THAT really is another entire tutorial! On these next few pages, we touch on some basics, just to get a little taste.

The <script> tag is used to define a client-side script, such as a JavaScript. The <script> element either contains scripting statements or it points to an external script file through the src attribute. The simple script below writes Hello JavaScript! into an HTML element with id="demo":

HTML file: Displayed by browser:
<!DOCTYPE html>
  <html>
    <body>

<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script>


    </body>
  </html>

Some browsers may be set to block scripts, so you may get a popup box asking if you want to allow the script to do its thing.

Back button Table of Contents Next button