Solved

Replacing html tags

Posted on 2011-03-10
6
175 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

786 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