Web Development

javaScript

JavaScript is the most popular programming language in the world.

It is the language for HTML, for the Web, for computers, servers, laptops, tablets, smart phones, and more.

This page contains some examples of what JavaScript can do in HTML.

The HTML DOM (the Document Object Model) is the official W3C standard for accessing HTML elements.

JavaScript can manipulate the DOM (change HTML contents).

You can use JavaScript to:

  • Change HTML elements

  • Delete HTML elements

  • Create new HTML elements

  • Copy and clone HTML elements

  • And much more ...

javascript code is written in the "script" tag in the html file. It can be wrutten anywhere in the file but is preffered at the bottom so that the page loads faster.

The following example changes the content (innerHTML) of an HTML element identified with id="demo" ie this example changes the text on the web page on the click of a button.:

Example:

<!DOCTYPE html>
<html>
<body>

<h1>My First JavaScript</h1>

<p>JavaScript can change the content of an HTML element:</p>

<button type="button" onclick="myFunction()">Click Me!</button>

<p id="demo">This is a demonstration.</p>

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

</body>
</html>

You can learn more about javascript at http://www.w3schools.com/js/