Link to home
Start Free TrialLog in
Avatar of ivanopalas
ivanopalas

asked on

replace all <span .... > </span> to < div ......> </div> everywhere on page by JavaScript

Hello!
I need to replace Span tags to div with all the same attributes. ( 'couse it;s not valid construction produced by DNN).

<span id="dnn_ctr831_ContentPane">
<div id="dnn_ctr831_ModuleContent">
<div id="dnn_ctr831_HtmlModule_HtmlModule_lblContent" class="Normal">
<img height="445" width="638" src="/Portals/8/how-we-get-4_03.jpg" alt="X" />
</div>
</div>
</span>

Please advise
ASKER CERTIFIED SOLUTION
Avatar of jwfranklin
jwfranklin

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
Avatar of ivanopalas
ivanopalas

ASKER

Thanks, but how to mke it OnLoad for Page? (not on click)
(inside the javascript) window.onload=display)

I've included this in the code below
<html>
	<head>
		<title>Test</title>
		<script type="text/javascript">
			function display() {
				var contents = document.getElementsByTagName('body')[0].innerHTML;
				contents = contents.replace(/<span/gi, "<div");
				contents = contents.replace(/<\/span/gi, "</div");
				document.getElementsByTagName('body')[0].innerHTML = contents;
				alert(contents);
			}
			window.onload=display;
		</script>
	</head>
	<body>
		<span id="test">
			<p>Hello world</p>
		</span>
		<span id="test2">
			<p>Hello again</p>
		</span>
	</body>
</html>

Open in new window