hankknight
asked on
JavaScript: Replace all HTML tags with placeholders
Inside <div id="content"></div> I want to replace all opening tags with **= and I want to replace all closing tags with =**
<!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>Title</title>
</head>
<body>
<div id="content">
<h1 class="h">Heading</h1>
<p>Hello <strong class="w">World</strong>.</p>
<p><span style="color: red">red</span> <span style="color: blue">blue</span> <span style="color: green">green</span></p>
</div>
<script type="text/javascript">
/*<![CDATA[*/
// Thanks, hielo
var obj=document.getElementById('content');
if(obj){
var tagsOpen=obj.innerHTML.match(/(<[a-zA-Z]+[^>]*?>)/g);
alert('Opening Tags: \n\n'+tagsOpen.join("\n"))
var tagsOpen=obj.innerHTML.match(/(<\/[a-zA-Z]+[^>]*?>)/g);
alert('Closing Tags: \n\n'+tagsOpen.join("\n"))
}
alert('
**=Heading=**
**=Hello **=World=**.=**
**=**=red=** **=blue=** **=green=**=**
');
/*]]>*/
</script>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.