User Rating: 2 / 5

Star ActiveStar ActiveStar InactiveStar InactiveStar Inactive
 

1. you can use the document.getElementById(id) method to access an HTML element from JavaScript.

Use the "id" attribute to identify the HTML element

benefits of Document.getElementById:

    (1). Available for access in the Form of an HTML Element Id in Attribute Id. 

    (2). Use for the management of various Element Object in HTML Form. 

    (3). Representation of Element Object access method such as value, focus, etc.. 

Example

<html>
<body>
<h1 id="demo">Tutorial</h1>
<script>
document.getElementById("demo").innerHTML="Mindphp.com";
</script>
</body>
</html>

This is the result:

The JavaScript is executed by the web Browser. In this case, the browser will access the HTML element with id="demo", and replace its content (innerHTML) with "Mindphp.com".

 

2. Document.write command

Is the command for printing text or information on the documentation page (Document) or on Elements such as requirements in JavaScript, which is written as A to print text on html document

Example:

<html>
<body>
<script>
document.write("<p>JavaScript</p>");
</script>
</body>
</html>

This is the result:

 

Next

Chapter 4 - JavaScript Statements