Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

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>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of StealthyDev
StealthyDev

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial