Requests and responses through which a web browser and web server communicate happen with HTTP
INLINE
INTERNAL
EXTERNAL
<!DOCTYPE html>
<html>
<head>
<script src="script.js"> </script>
</head>
<body>
<div onclick="window.alert("Triggered by Inline JS")"> Click Me </div>
<script>
document.getElementsByTagName('div')[0].addEventListener('click', function(){
document.getElementsByTagName('div')[0].innerHTML ="Triggered by internal JS";
});
</script>
</body>
</html>
INLINE
INTERNAL
EXTERNAL
INLINE
INTERNAL
EXTERNAL
<script>
document.getElementsByTagName('div')[0].addEventListener('click', function(){
document.getElementsByTagName('div')[0].innerHTML ="Triggered by internal JS";
});
</script>
INLINE
INTERNAL
EXTERNAL
<script src="script.js"> </script>
<script src="script.js" defer> </script>
async
and defer
attributes can be added to script element to modify its sequence of processingasync
attribute tells a browser to parse the HTML and JavaScript code togetherdefer
attribute defers script processing until after the page has been completely parsed and loaded
<!DOCTYPE html>
<html>
<head>
<title>Incorporating JS - INLINE </title>
</head>
<body>
<div onclick="window.alert("Triggered by Inline JS")"> Click Me </div>
</body>
</html>
Apply the following bullet points to the HTML code below.
Comments help understand the design and purpose of programs
JavaScript comments can be entered on single or multiple lines
// This is example of single line text
/* This is an example of a comment block
that can span multiple lines.
*/
<!DOCTYPE html>
<html>
<head>
<title>Simple JS program </title>
</head>
<body>
<script> //JS statements go here </script>
</body>
</html>
Apply the following bullet points to the HTML code below.
With the Document Object Model, programmers can create and build documents, navigate their structure, and add, modify, or delete elements and content.
Commenting out Code
Logging output to Console
Browser and Editor Debugging
The three above techniques can be used in conjunction.
Step 1
Render the html document in the browser and inspect elements by pressing "F12" and click on the "Sources" tab and navigate folder structure in left panel.
Step 2
Select JS file you would like to debug and create breakpoint on a line within the middle panel that displays the script.
Step 3
Peform an action that would involk code to run and observe variable assignment.