?
Solved

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

Posted on 2008-10-27
3
Medium Priority
?
534 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 500 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
This article discusses how to create an extensible mechanism for linked drop downs.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

770 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