Displays the html tags without rendering on a webpage.
Display html tags on a webpage
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<script type="text/javascript">
function firstMethod()
{
var str = document.getElementById("tbl").innerHTML.replace(/[<]/g,'<');
str = str.replace(/[>]/g,'>');
document.getElementById("displayHTML").innerHTML = str;
}
function secondMethod()
{
document.getElementById("displayHTML").innerText = document.getElementById("tbl").innerHTML;
}
</script>
</head>
<body>
<div id="displayHTML"></div>
<table border="1" id="tbl">
<tr>
<td style="width: 100px">
1</td>
<td style="width: 100px">
2</td>
<td style="width: 100px">
3</td>
</tr>
<tr>
<td style="width: 100px">
4</td>
<td style="width: 100px">
5</td>
<td style="width: 100px">
6</td>
</tr>
<tr>
<td style="width: 100px">
7</td>
<td style="width: 100px">
8</td>
<td style="width: 100px">
9</td>
</tr>
</table>
<input type="button" value="use conventional method" onclick="firstMethod()" />
<input type="button" value="use serkan's method" onclick="secondMethod()" />
</body>
</html>
This is a good example of using javascript innerText property which is not
as popular as innerHTML property.
Troy III
272
Posting Pro
serkan sendur
821
Postaholic
Banned
Troy III
272
Posting Pro
serkan sendur
821
Postaholic
Banned
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.