Loading Please Wait...

Logo Lynxsia IT Solutions

JavaScript HTML DOM HTML

JS HTML DOM HTML

The HTML DOM allows JavaScript to change the content of HTML elements.

Changing HTML Content

The easiest way to modify the content of an HTML element is by using the innerHTML property.

					 
        
          <html>
            <body>
              <p id="p1">Hello World!</p>
              <script>
                document.getElementById("p1").innerHTML = "New text!";
              </script>
            </body>
          </html>
        
      
Changing the Value of an Attribute

To change the value of an HTML attribute, you can use attribute properties such as src, name, href, etc.

					 
        
          <html>
            <body>
              <img id="myImage" src="image-1.png">
              <script>
                document.getElementById("myImage").src = "image-2.png";
              </script>
            </body>
          </html>
        
      
Dynamic HTML content

JavaScript can create dynamic HTML content.

					 
        
          <html>
            <body>
              <p id="myPara"></p>
              <script>
                document.getElementById("myPara").innerHTML = "Date : " + Date(); 
              </script>
            </body>
          </html>
        
      
document.write()

In JavaScript, document.write() can be used to write directly to the HTML output stream

					 
        
          <html>
            <body>
              <p>Paragraph 1</p>
              <script>
                document.write(Date());
              </script>
              <p>Paragraph 2</p>
            </body>
          </html>
        
      
Never use document.write() after the document is loaded. It will overwrite the document.

How you feel about this blog:

Share this blog on:

Report Us

If you find any error in the turtorials, or want to share your suggestion/feedback, feel free to send us email at: info@lynxsia.com

Contact Us
Ads
Logo
Lynxsia IT Solutions

We are concern with various development process like website design & development, E-commerce development, Software development, Application development, SMS & Bulk SMS Provider, PWA Development, and many more..

Kotwali Road, Chhiptehri, Banda, 210001, UP, India

Copyright © 2022, Lynxsia IT Solutions, All rights reserved