Solved

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

Posted on 2008-10-27
3
533 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

724 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