JS Lesson1
JS Lesson1
Tutorials
Part 1: An Introduction
What’s in?
1. What is JavaScript?
2. What are the Requirements?
3. How do we use JavaScript?
JavaScript
Is a programming language for
designing websites. It can
manipulate both HTML and CSS
JavaScript
It can perform logical checks,
calculation, modify existing HTML
and CSS codes and more.
JavaScript
It is the most populat
programming language as of the
moment.
Requirements
1. Text Editor
2. Browser
Text Editor
Browser
Where to place JavaScript?
1. Script inside the BODY section
2. Script inside the HEAD section
3. External Script
Script inside the Body Section
<!DOCTYPE html>
<html>
<body>
<h2>Demo JavaScript in Body</h2>
<p id="demo">A Paragraph</p>
<button type="button" onclick="myFunction()">Try it</button>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Paragraph
changed.";
}
</script>
</body>
</html>
Script inside the Head Section
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Paragraph
changed.";
}
</script>
</head>
<body><h2>Demo JavaScript in Head</h2>
<p id="demo">A Paragraph</p>
<button type="button" onclick="myFunction()">Try it</button>
</body>
</html>
External Script
<!DOCTYPE html>
<html>
<head> function myFunction() {
<script src=“script.js”> document.getElementById("demo"
</script> ).innerHTML = "Paragraph
</head> changed.";
<body><h2>External }
JavaScript</h2>
<p id="demo">A Paragraph</p>
<button type="button" onclick=
"myFunction()">Try it</button>
</body>
</html>