473,387 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

DIV content not display when created with Javascript

4
My environment:

IE7 browser hitting an ASP.NET webpage that uses Javascript to render the contents. This is not an ASP.NET problem but a Javascript problem that I am encountering.

Problem:

I am basically generating a menu which is essentially a TABLE within a DIV tag using Javascript. For some reason the table is not displaying. The DIV tag essentially has the dimensions of 0.

What I have done:

The first thing you're probably asking is, "your script is probably not working." I have verified that the code is indeed correct. In my IE7 environment, I have installed the developer toolbar and verified that the HTML is being created by the script and it looks correct.

The next thing you're probably asking is, "you have some funky style settings which is why it's not display." I have verified that the elements created are correct by copying the EXACT html code that is created (using the developer toolbar) and pasting it inside the same page and loading it. Viola, it displays just as expected and rendered perfectly.

I have also tried to resize the DIV tag (when generated with javascript) in the developer toolbar and no contents are displayed inside of it. It's just one blank div even though when you look at the DOM, the elements are there.

The HTML elements being generated is similar to the following:

<div>
<table>
<tr><td>Item 1</td></tr>
<tr><td>Item 2</td></tr>
<tr><td>Item 3</td></tr>
<tr><td>Item 4</td></tr>
</table>
</div>

Thanks
Mar 27 '08 #1
5 1430
gyip
4
One thing that might be important is that the DOCTYPE is the following:

<!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">
Mar 27 '08 #2
gyip
4
After bashing my head for 3 days and searching hundreds of pages across the internet which lead me to my original post, I finally figured it out.

I found a great article published on MSDN titled "How to Build Tables Dynamically": http://msdn2.microsoft.com/en-us/lib...98(VS.85).aspx

It states the following:

Note Internet Explorer requires that you create a tBody element and insert it into the table when using the DOM. Since you are manipulating the document tree directly, Internet Explorer does not create the tBody, which is automatically implied when using HTML.

I hope this helps other people.
Mar 27 '08 #3
hsriat
1,654 Expert 1GB
Thanks for that information.

Was it working on FireFox (without tbody)?


Regards,
Harpreet
Mar 27 '08 #4
gyip
4
The weird thing is that Firefox was inconsistant. Because I actually have a table within a table within a div. And the first table rendered in Firefox but not the second which also confused me. Versus IE, which didn't render anything at all. This also explains why cut and pasting of the html into the page works.

I also found several other posts elsewhere where people had the same problem but I never found a post with the conclusion that I mentioned above. You will see some random people saying to use table.insertRow() or table.insertCell() to create the TR/TD tags instead of document.createElement() but that is just a shortcut for:

var tr = document.createElement('tr');
table.appendChild(tr);
Mar 27 '08 #5
acoder
16,027 Expert Mod 8TB
The weird thing is that Firefox was inconsistant. Because I actually have a table within a table within a div. And the first table rendered in Firefox but not the second which also confused me. Versus IE, which didn't render anything at all. This also explains why cut and pasting of the html into the page works.
You must have made a mistake somewhere.

The article that you posted has a very bad coding style. Non-standard and buggy probably only tested in IE.
Apr 1 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Brian Vallelunga | last post by:
Greetings, I'm attempting to create a tabbed box with CSS and Javascript and am having some problems. I have three tabs and three tab content areas. When the page is loaded, two of the three...
0
by: Jimmy Cerra | last post by:
I recently came up with a cool little stylesheet for definition lists. There is a small demostration for the impatient . I hope this helps someone. Here's how I did it. Definition lists are...
1
by: Izzet Pembeci | last post by:
I am trying to display some rss feeds in my homepage. To do that I am using an external script which returns smth like: document.writeln("<div ...>") document.writeln("Title of News 1") !! read...
10
by: clintonG | last post by:
Can somebody direct me to documents or source that supports the use of collapsible content that is collapsed by default when the page is loaded? The secondary objective would of course be...
7
by: Ryan Taylor | last post by:
Hi. I have some code that dynamically generates a PDF and spits this content directly to the web browser. I use HTMLDoc to create the Pdf's from html. So the user can click on a button "Print...
2
by: Ruskin Hardie | last post by:
There is an iframe in my document that is hidden, which is the target for a submitted form. When the form is submitted, some javascript sets a hidden div, to displaying, eg: ...
6
by: Pete Verdon | last post by:
Summary: Can I do an XSLT transform, in the client, of a tree of nodes taken from the displayed page DOM in IE? This works in Firefox. Hi, I'm just starting the process of rewriting part of a...
8
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web...
9
by: pbd22 | last post by:
Hi. This is just a disaster management question. I am using XMLHTTP for the dynamic loading of content in a very crucial area of my web site. Same as an IFrame, but using XMLHTTP and a DIV. I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.