Solved

Replacing html tags

Posted on 2011-03-10
6
176 Views
Last Modified: 2012-05-11
Having a table with id tag like below
<table id=tesTable>

If  screen size < 480px
{
Run a javascript to (
   Search tag for  table excluding id
  And replace with div)
}
Else
   Keeps table tag

Any help with code for this is greatly appreciated
0
Comment
Question by:zrazak
6 Comments
 
LVL 6

Expert Comment

by:Webmonkey
ID: 35100368
And you're wanting to do this in what language?
0
 

Author Comment

by:zrazak
ID: 35100433
In javascript
0
 
LVL 4

Expert Comment

by:RawElements
ID: 35108484
Any reason why the original markup can't lose the table?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 

Author Comment

by:zrazak
ID: 35108855
well I dont want to change the original code its for desktop website and want toreplace the table tags with div tags  for viewing purposes on mobile devices thus not technically replacing the actual code
0
 
LVL 4

Expert Comment

by:RawElements
ID: 35109756
It just seems like a hard way to do what should be a relatively easy job. Do you have a test page available for viewing?
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 35113658
With jQuery :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.5.min.js"></script>
<script language="javascript">
	$(document).ready(function() {
		$("table").each(function() {
			$(this).replaceWith("<div id=\"" + $(this).attr("id") + "\">" +  $(this).html() + "</div>") 
		});
	});
</script>
</head>
<body>
<table id="tesTable"><tr height="396"><td width="640">tesTable</td></tr></table>
<br/>
<table id="notesTable"><tr><td>notesTable</td></tr></table>
</body>
</html>

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Title # Comments Views Activity
tiny glitch in my main slider 3 38
html Uncheck Checkbox 2 25
removing a class in javascript 4 47
Bootstrap list items overlap 3 7
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

808 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