Lab03 Javascript 2021
Lab03 Javascript 2021
<!DOCTYPE html>
<html>
<body>
<script>
document.write("Hello World, I’m writing my First
JavaScript");
</script>
</body>
</html>
b) Add the following line getElementById() method to return the element that has the ID
attribute (i.e. <p id=”demo”> inside the <script> tag. Use it together with the innerHTML
property to set or return the HTML content of an element. Add the line <p id="demo"
style="color:blue"></p> inside the body. Can you see the output? Change the position of
the <p> element to test your script.
<script>
document.getElementById("demo").innerHTML = "This output is
written using innerHTML";
</script>
1
2. Task 2: JavaScript: Variables, Operators, Arithmetic, Assignments and Functions.
a) Write the following code in a file called Lab03_2.html and observe the behaviors.
<!DOCTYPE html>
<html>
<head>
<script>
/*Block comment*/
function myFunction1() {
document.getElementById("p1").innerHTML = "Paragraph changed
using p1.";
}
//this is one-line comment
function myFunction2(str) {
document.getElementById("p2").innerHTML = str;
}