Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

Dynamic HTML content

JavaScript can generate dynamic HTML content:

Date: Mon, Nov 18, 2024 12:46:21 GMT+0530 (India Standard Time)

Example

<!DOCTYPE html>
<html>
<body>

<script>
document.getElementById(“demo”).innerHTML = “Date : “ + Date(); 
</script>

</body>
</html>

document.write()

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

Example

<!DOCTYPE html>
<html>
<body>

<p>Bla bla bla</p>

<script>
document.write(Date());
</script>

<p>Bla bla bla</p>

</body>
</html>

Avoid using document.write() after the document has loaded, as it will overwrite the entire document.