How to insert the data in a web page dynamically?
To insert the data in a web page dynamically use <div></div> tag or <span></span> tag
The data inserted with <div></div> goes to new line. It is a block tag.
The data inserted using <span></span> tag remains in same line. It is inline tag.
Define an ID to these tags and get reference of that ID using document.getElementById() function
Use innerHTML property to insert HTML contents
Use innerText properyt to insert the Text contents.
Example 1
Create a web page having a multiline text box using <textarea></textarea> tag. When we type some HTML code into the web page, show the code along with its output in same web page.
Hint: Event will be keyup
Example 2
Create a web page having a text box to input a number.
Show the factorial of that number when a number is typed in front of the text box.
The output format will be like
The factorial of <num> is <factorial>
<!DOCTYPE html>
Comments
Post a Comment