Javascript

JavaScript is a scripting language used to add interactivity and functionality to a webpage.

JavaScript is a scripting language is a language that supports scripts. Scripting languages are written for a particular environment and JavaScript is a scripting language used on the web.

JavaScript is called a client-side scripting language because the program is run by the ‘client’ – your Browser.

JavaScript Events

An event is when a particular action occurs such as:

  • The user pressing a key or mouse button

  • The page has loaded

  • A form has been submitted

  • A document has been resized


When one of these actions (events) have occurred then a particular piece of code can be executed.

Mouse Events

onClick

triggers when the user clicks on an element

ondblClick

triggers when the user clicks on an element

onmouseOver

triggers when the user moves the cursor over an element

onmouseOut

triggers when the user moves a cursor away from/out of an element

MouseOver/Out Script

The <script> and </script> tags are used to let the browser know that anything contained between these tags is written in JavaScript.

Within the <script> and </script> tags it is possible to write JavaScript code or link to an external JavaScript file.

<script>

function mouseOver() {

document.getElementById("demo").style.color = "red"}

function mouseOut() {

document.getElementById("demo").style.color = "black";

}

</script>