Solved

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

Posted on 2008-10-27
3
526 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
Comment Utility
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
Comment Utility
Thanks, but how to mke it OnLoad for Page? (not on click)
0
 
LVL 1

Expert Comment

by:jwfranklin
Comment Utility
(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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now