JavaScript Display Possibilities

JavaScript can "display" data in different ways and here we discuss innerHTML and document.write.

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

 

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:

Example:

Using document.write()

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

The write() method writes HTML expressions or JavaScript code to a document. The write() method is mostly used for testing: If it is used after an HTML document is fully loaded, it will delete all existing HTML.

Example:

Example

Write some text directly to the HTML document, with a new line after each statement (using <br>):

document.write("Hello World! <br>");
document.write("Have a nice day!");

Example

Write HTML elements with text directly to the HTML document:???

document.write("<h1>Hello World!</h1><p>Have a nice day!</p>");

Example

Write the Date object directly to the HTML:

document.write(Date());

 

Working hours

 

Day Timing
Monday To Friday 8:00 Am To 8:00Pm
Saturday & Sunday 8:00 Am To 5:00Pm
 
 

Contact Information
ADDRESS: 263, First Floor
Pocket H-17, Sector 7
Rohini, Delhi - 110085
Near Rohini West Metro Station
Opposite Metro Pillar No. 425

Email: contactbapugraphics@gmail.com
            bapugraphicsindia@gmail.com

Mobile: 9891222738

Copyright © 2014 Bapu Graphics, All Right Reserved.