Javascript output
JavaScript Display Possibilities
JavaScript can "display" data in different ways:
- Writing into an HTML element, using
innerHTML
. - Writing into the HTML output using
document.write()
. - Writing into an alert box, using
window.alert()
. - Writing into the browser console, using
console.log()
.
Using innerHTML
To access an HTML element, JavaScript can use the
document.getElementById(id)
method.
The
id
attribute defines the HTML element. The innerHTML
property defines the HTML content:
<h2>My First Web Page</h2>
<p>My First Paragraph.</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 7 + 5;
</script>
0 ŠŗŠ¾Š¼Š¼ŠµŠ½Ń.