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.
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.
triggers when the user clicks on an element
triggers when the user clicks on an element
triggers when the user moves the cursor over an element
triggers when the user moves a cursor away from/out of an element
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>