Solved

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

Posted on 2008-10-27
3
530 Views
Last Modified: 2013-11-19
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
0
Comment
Question by:ivanopalas
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
jwfranklin earned 125 total points
ID: 22811663
Hello

I have a solution which involves replacing the text <span & </span with <div and </div, see the code snippet below. Hope it's what you're after.
<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;
			}
		</script>
	</head>
	<body>
		<span id="test">
			<p>Hello world</p>
		</span>
		<span id="test2">
			<p>Hello again</p>
		</span>
		<a href="#" onclick="display()">click me</a>
	</body>
</html>

Open in new window

0
 

Author Closing Comment

by:ivanopalas
ID: 31510246
Thanks, but how to mke it OnLoad for Page? (not on click)
0
 
LVL 1

Expert Comment

by:jwfranklin
ID: 22811783
(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

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question