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
Solved

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

Posted on 2008-10-27
3
531 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
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 receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

860 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