HomeTutorialsHTML Intermediate Tutorial

Javascript

Javascript is a client-side scripting language that can work in conjunction with HTML and while this is not a Javascript guide, we can look at how HTML can use Javascript.

HTML Dog, The Book HTML Dog book cover

HTML Dog is hosted by Titan Internet

Javascript events can be used like attributes in HTML tags. An event is something that happens to that HTML element, such as when it is 'clicked' or when it loses focus.


<a href="#top" onclick="alert ('wow. Javascript.')">Click me</a>

The events that can be used are:

  • onblur (used in form elements and executed when an element loses focus)
  • onchange (used in form elements and executed when something is changed)
  • onclick (executed when a mouse is clicked on an element)
  • ondblclick (executed when a mouse is double-clicked on an element)
  • onfocus (used in form elements and executed when an element gains focus)
  • onkeydown (executed when a key is pressed down)
  • onkeypress (executed when a key is pressed and released)
  • onkeyup (executed when a key is released)
  • onload (used in the body tag and executed when the page loads)
  • onmousedown (executed when the button of a mouse is pressed down)
  • onmousemove (executed when the mouse cursor moves on an element)
  • onmouseout (executed when the mouse cursor moves away from an element)
  • onmouseover (executed when mouse cursor moves over an element)
  • onmouseup (executed when the button of a mouse is released)
  • onreset (used in form elements and executed when a form is reset)
  • onselect (used in form elements and executed when an element is selected)
  • onsubmit (used in form elements and executed when a form is submitted)
  • onunload (used in the body tag and executed when the user navigates away from the page)

Phew.

Try not to get carried away with Javascript. It's best uses tend to be small additions of functionality. There is a danger of seriously degrading the accessibility of a web page with Javascript, and many things that it can be used for can be replaced with server-side scripting languages such as PHP or ASP.