Display Output in Java Script

Learn how to display data in different ways using Java Script

Display Possibilities
1. innerHTML: returns Java script Output value to a html tag
2. Document.Write : This will write string directly on browser.
3. Alert : it Will display string in form of Dialog box
4. Confirm: This can be used to display confirmation dialog box. It returns Boolean value i.e true/false
5. console.log(): It is used for debugging purposes.

Java script Example to display data in html element

  1. To access an HTML element, JavaScript can use the document.getElementById(id) method
  2. The id attribute defines the HTML element. The innerHTML property defines the HTML content:
<html >
<head>
    <title></title>
</head>
<body>
    <p id="pg1"></p>
    <script type="text/javascript">
        document.getElementById("pg1").innerHTML="Writing data into an HTML element using inner HTML "
    </script>
</body>
</html>

Java script Example to display data using document and Window objects

<html >
<head>
    <title></title>
</head>
<body>
    <script type="text/javascript">
        document.write("This is the form write of Document Object <br/>");
        alert("This is form alert of Window Object");
        confirm("This is form Confirm of Window Object");
        console.log(5 + 6);
    </script>
</body>
</html>


Leave a Comment