JavaScript innerHTML document.write() window.alert() - Javascript

JavaScript innerHTML document.write() window.alert()

JavaScript innerHTML document.write() window.alert()

In this Blog You will learn about the JavaScript innerHTML document.write() window.alert(). Here you will learn all these methods with examples. So Must check the full Article. 

JavaScript Display Possibilities

JavaScript can “display” data in different ways:

  • Writing into an HTML element, using innerHTML.
  • Writing into the HTML output using write().
  • Writing into an alert box, using alert().

Using innerHTML

To access an HTML element, JavaScript can usethe document.getElementById(id) method.The id attribute defines the HTML element. The innerHTML property defines the HTML content:

Example

<html>
<body>
<h1>My First Web Page</h1>
<p>My First Paragraph</p>
<p id=”demo”></p>
<script> document.getElementById(“demo”).innerHTML = 15 + 6;
</script>
</body>
</html>

Output

 

Subscribe Our Youtube Channel For Live Class link is given below-

https://www.youtube.com/@olevelguruji

Using document.write()

For testing purposes, it is convenient to use document.write():

Example

<html>
<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<script>
document.write(“This is document.write() function example<br>”);
document.write(“Addition of 55+6 is ” +(55+ 6));
</script>
</body>
</html>

Output

 

 

JavaScript innerHTML document.write() window.alert()

<html>

<body>

<h1>My First Web Page</h1>

<p>My first paragraph.</p>

<button type=”button” onclick=”document.write(5 + 6)”>Try it</button>

</body>

</html>

Using window.alert()

You can use an alert box to display data:

Example

<html>
<body>
<h1>My First Web Page</h1>
<p>My first paragraph.</p>
<script>
window.alert(55 + 65);
</script>
</body>
</html>

Output

JavaScript innerHTML document.write() window.alert()You can skip the window keyword.

In JavaScript, the window object is the global scope object, that means that variables, properties, and methods by default belong to the window object. This also means that specifying the window keyword is optional:

JavaScript Print

JavaScript does not have any print object or print methods. You cannot access output devices from JavaScript.

The only exception is that you can call the window.print() method in the browser to print the content of the current window.

Example

<html>
<body>
<button onclick=”window.print()”>Print this page</button><br>
welcome to window.print() method in javascript…
</body>
</html>

Output

When we click on the Print this page button then you will get the Output

JavaScript innerHTML document.write() window.alert()

Also Check Our Latest Uploads

javascript variables and data types

concept of JavaScript?

client-side scripting language and server-side scripting

 

1 thought on “JavaScript innerHTML document.write() window.alert()”

Leave a Comment