Java Script Codes Grade 12 Bi
Java Script Codes Grade 12 Bi
document.write(“hello”)
</script>
Example: <html>
<body>
<p ID = “Paragraph1” > </p>
<script>
document.getElementByld (“Paragraph1”).innerHTML “hello world”
</script>
</body>
</html>
var answer = confirm (“ ok to next step”) A confirm box has two options: ok and
cancel
var result = prompt (“ What is your name ?”) A prompt box will allow the user to
enter some text and give them the
option of ok and cancel
console.log (“ alert”) It helps to track the flow of their code
and identify issues, its for debugging
<img src ="" id ="img1"> The <img> tag in HTML adds an
image to a web page.
The src attribute tells the browser
where to find the image,
and the id attribute gives the image a
unique name so you can style or
control it with JavaScript.
Example:
<html>
<body>
<img src ="" id ="img1">
<script>
document.getElementById("img1").src = " 6.JPEG"
</script>
</body>
</html>
document.getElementById ("p1") .style .fontSize = "x-large" To change the font size of the
paragraph
document.getElementById ("p1") .style .fontFamily = "Arial" To change the font family of the
paragraph (Arila , Calibri)
document.getElementById ("p1") .style .fontWeight = "bold" To change the font weight of the
paragraph (Bold ,lighter, normal)
document.getElementById ("p1") .style.backgroundColor = To change the paragraph background
"yellow” color
Example:
<html>
<body>
<p id = "p1" > This is my first paragraph </p>
<p id = "p2" > This is my second paragraph</p>
<script>
document.getElementById ("p1") . style .color = "blue"
document.getElementById ("p1") . style .fontSize = "x-large"
document.getElementById ("p1") . style .fontFamily = "Arial"
document.getElementById ("p1") . style .fontWeight = "bold"
document.getElementById ("p1") .style.backgroundColor = "yellow"
document.getElementById ("p2") . style .color = "green"
</script>
</body>
</html>