- The innerText property can be used to write the dynamic text on the html document.
- In this example, we are wrote text with <b> tag but it won't render as html.
- It is used mostly in the web pages to generate the dynamic content such as writing the validation message, password strength etc.
Code:-
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="t_div">Old Text</div>
<button type="button" onclick="set_txt();">Change Text</button>
<script>
function set_txt()
{
document.getElementById("t_div").innerText = "<b>New Text</b>";
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="t_div">Old Text</div>
<button type="button" onclick="set_txt();">Change Text</button>
<script>
function set_txt()
{
document.getElementById("t_div").innerText = "<b>New Text</b>";
}
</script>
</body>
</html>
JavaScript:- what is a inner text.
Reviewed by Network security
on
May 30, 2019
Rating:
No comments: