Table of Contents
JavaScript
Document JavaScript HTML methods.
Overview
In HTML, JavaScript code is inserted between <script>
and </script>
tags.
<script>
document.getElementById("demo").innerHTML = "My First JavaScript";
</script>
JavaScript is the default scripting language in HTML if
type
attribute is not specified.
That is, the code below has the same effect as the code above.
<script type="text/javascript">
document.getElementById("demo").innerHTML = "My First JavaScript";
</script>
Keywords
Keyword | Description |
---|---|
var | Declares a variable (It should only be used if MUST support old browsers.) |
let | Declares a block variable |
const | Declares a block constant |
if | Marks a block of statements to be executed on a condition |
switch | Marks a block of statements to be executed in different cases |
for | Marks a block of statements to be executed in a loop |
function | Declares a function |
return | Exits a function |
try | Implements error handling to a block of statements |
HTML Element
Objects
document
Property | Description |
---|---|
innerHTML | HTML content. |
Function | Description |
---|---|
getElementById(string) | Find an HTML element by id attribute. |
write(string) | Write content to HTML. This function should only be used for testing |
window
Function | Description |
---|---|
alert(string) | Call up an alert box to display the data. |
print() | Print the content of the current window. |
Debug Method
console.log()