Javascript in the browser getting started page.
In a web page, Javascript is modifying the HTML dom (the browser representation of the HTML page).
With the Web Dom API, you handle one DOM element at a time but with processor libraries such as D3, jQuery, you instead handle groups of related elements.
You can run Javascript directly from the Browser Console
In a HTML page, JavaScript can be found:
Javascript code is executed in order of appearance
If the Javascript code is supposed to affect the [web:dom:body|body of the DOM (ie the body of an HTML page)]], it should then be placed after the element that should be modified (generally the script is placed before the end of the body)
Example:
index.html
lib.js
<html>
<body>
<!--- The HTML --->
<script src="lib.js" type="application/javascript"></script>
</body>
</html>
// javascript code
Example: Adding Hello to the text of an H1 element
var myHeading = document.querySelector("h1");
myHeading.textContent = "Hello "+myHeading.textContent+"!";
<h1>World</h1>
With the DOM append method, we can add an element.
Example: Adding an H1 element
var div = document.createElement("h1");
div.innerHTML = "Hello, world!";
document.body.appendChild(div);
<!-- Empty body -->