473,466 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Style setting for generated DIVs

Hello,

I'm writing a web application where I want to load bits of data at
runtime from the client end (via AJAX). The loading of the data part
works great, but for some reason anytime I try to impart a style
setting (via either putting it inline, a CSS, or through javascript)
the DIV completely ignores my setting. The setting most importantly I'm
trying to apply is display: none, but none of them work.

If I pre-create everything (straight html) all the style changes and
methods work fine, just not on generated DIVs.

TIA,
Randy

Mar 23 '06 #1
5 1364

ve*****@gmail.com wrote:
Hello,

I'm writing a web application where I want to load bits of data at
runtime from the client end (via AJAX). The loading of the data part
works great, but for some reason anytime I try to impart a style
setting (via either putting it inline, a CSS, or through javascript)
the DIV completely ignores my setting. The setting most importantly I'm
trying to apply is display: none, but none of them work.

If I pre-create everything (straight html) all the style changes and
methods work fine, just not on generated DIVs.

TIA,
Randy


To help you get started, it would be nice if you at least gave us a
snippet of the code that is supposed to do all that you say. Then we
can try to diagnose the problem.

Mar 23 '06 #2
Here's the code that does all the work (sorry for the lack of
commenting, I haven't gotten there yet):

function fillContent(url, obj) {

var http_request = false;

if( window.XMLHttpRequest ) { // Mozilla, Safari, ...
http_request = new XMLHttpRequest();
if( http_request.overrideMimeType ) {
http_request.overrideMimeType('text/xml');
}
} else if( window.ActiveXObject ) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch( e ) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch( e ) {}
}
}

if( !http_request ) {
alert('Giving up: (Cannot create an XMLHTTP instance');
return false;
}

http_request.onreadystatechange = function() {
alertContents(http_request, obj); };
http_request.open('GET', url, true);
http_request.send(null);

return false;

}

function alertContents(http_request, obj) {

if( http_request.readyState == 4 )
{
if( http_request.status == 200 )
{
var xmldoc = http_request.responseXML;
var root = xmldoc.getElementsByTagName('root');
if( root[0].getAttribute("id") == "Product List" )
{
showProdList(root, obj);
}
} else {
alert('There was a problem with the request.');
alert(http_request.status);
}
}

}

function showProdList(root, obj)
{
var prods = root[0].childNodes;
obj.innerHTML = "";
for( var i=0; i<prods.length; i++ )
{
drawProduct( prods[i], 0, obj );
}
}

function drawProduct(ele, level, obj)
{
var space = "";
for( var sp=0; sp<level; sp++ )
{
space += "&nbsp;&nbsp;";
}

var dispName = new String( ele.getAttribute("id") );
var id = new String();
var imgSrc = new String( "images/folder.gif" );
for( var sl=0; sl<dispName.length; sl++ )
{
if( dispName.charAt(sl) != " " && dispName.charAt(sl) != "." )
{
id += dispName.charAt(sl);
}
}

var ch = ele.getElementsByTagName("product");
if( ch.length < 1 )
{
imgSrc = "images/text.gif";
}

obj.innerHTML += " <a id=\"x" + id + "\"
href=\"javascript:Toggle('" + id + "');\">";
obj.innerHTML += " <img src='" + imgSrc + "' width='16'
height='16' hspace='0' vspace='0' border='0'>";
obj.innerHTML += " </a>";
obj.innerHTML += " <b>" + dispName + "</b><br/>";
obj.innerHTML += "<div id='" + id + "' class=\"subitem\">";
var children = ele.childNodes;
for( var i=0; i<children.length; i++ )
{
if( children[i].getAttribute("parent") == ele.getAttribute("id")
)
{
drawProduct( children[i], level+1, obj );
}
}

obj.innerHTML += "</div>";
}

Mar 23 '06 #3
Here's the version of the actual drawing function that includes inline
style information instead of a class in a CSS...

function drawProduct(ele, level, obj)
{
var space = "";
for( var sp=0; sp<level; sp++ )
{
space += "&nbsp;&nbsp;";
}

var dispName = new String( ele.getAttribute("id") );
var id = new String();
var imgSrc = new String( "images/folder.gif" );
for( var sl=0; sl<dispName.length; sl++ )
{
if( dispName.charAt(sl) != " " && dispName.charAt(sl) != "." )
{
id += dispName.charAt(sl);
}
}

var ch = ele.getElementsByTagName("product");
if( ch.length < 1 )
{
imgSrc = "images/text.gif";
}

obj.innerHTML += " <a id=\"x" + id + "\"
href=\"javascript:Toggle('" + id + "');\">";
obj.innerHTML += " <img src='" + imgSrc + "' width='16'
height='16' hspace='0' vspace='0' border='0'>";
obj.innerHTML += " </a>";
obj.innerHTML += " <b>" + dispName + "</b><br/>";
obj.innerHTML += "<div id='" + id + "' style=\" display: none;
margin-left: 2em\">";
var children = ele.childNodes;
for( var i=0; i<children.length; i++ )
{
if( children[i].getAttribute("parent") == ele.getAttribute("id")
)
{
drawProduct( children[i], level+1, obj );
}
}

obj.innerHTML += "</div>";
}

Mar 23 '06 #4
Actually... I -may- have found an answer to my problem. Instead of
using innerHTML, it looks like it might work better creating a div
element and using appendChild. Still have to work with it a little more
to see if it will work.

Mar 23 '06 #5
Okay, it does work now. Here are the two functions I changed for
reference:

function showProdList(root, obj)
{
var prods = root[0].childNodes;
obj.innerHTML = "";

var d = document.createElement("div");
d.className = "subitem";
obj.appendChild( d );

for( var i=0; i<prods.length; i++ )
{
drawProduct( prods[i], 0, d );
}
}

function drawProduct(ele, level, obj)
{
var space = "";
for( var sp=0; sp<level; sp++ )
{
space += "&nbsp;&nbsp;";
}

var dispName = new String( ele.getAttribute("id") );
var id = new String();
var imgSrc = new String( "images/folder.gif" );
for( var sl=0; sl<dispName.length; sl++ )
{
if( dispName.charAt(sl) != " " && dispName.charAt(sl) != "." )
{
id += dispName.charAt(sl);
}
}

var ch = ele.getElementsByTagName("product");
if( ch.length < 1 )
{
imgSrc = "images/text.gif";
}
if( imgSrc == "images/text.gif" )
{
obj.innerHTML += " <img src='" + imgSrc + "' width='16'
height='16' hspace='0' vspace='0' border='0'>";
}
else
{
obj.innerHTML += " <a id='x" + id + "'
href=\"javascript:Toggle('" + id + "');\"><img src='" + imgSrc + "'
width='16' height='16' hspace='0' vspace='0' border='0'></a>";
}
obj.innerHTML += " <b>" + dispName + "</b><br/>";

var d = document.createElement("div");
d.id = id;
d.style.display = "none";
d.style.marginLeft = "2em";
d.className = "subitem";
obj.appendChild( d );

var children = ele.childNodes;
for( var i=0; i<children.length; i++ )
{
if( children[i].getAttribute("parent") == ele.getAttribute("id")
)
{
drawProduct( children[i], level+1, d );
}
}

}

Mar 23 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div...
14
by: Charlie T | last post by:
Hello, is there any way to get this to work? myID.innerHTML = "Hello" <DIV id="myID"></DIV> <DIV id="myID"></DIV>
9
by: lkrubner | last post by:
How do I get all the div's on a page? I realize in IE I can use document.all. For the other browsers, I need to get an array of all the divs on the page. getElementByTagName()?????
9
by: Chandy | last post by:
Hi, Is there any way to apply a style that will effectively block the application of any applied or inherited styles for that object and any contained objects? E.g., CSS: P {backgro...}
4
by: Michael | last post by:
Dear all .. If I want to use develop a user control and declare a public property which the type is System.Windows.Forms.GridTableStylesCollection For example : Public Class LookAndView...
1
by: 00steve | last post by:
Hi, I am attempting to apply an zoom style to a series of embedded divs. Each of the divs in the hierarchy has positioning (left, top, width and height) applyed to it via id selectors. When I...
3
by: Erwin Moller | last post by:
Hi all, Situation: A (rather long) page that contains a lot of divs. Some are visible (display:inline) at a certain time, other not. The javascript is responsible for divs to be visible or...
3
by: Rick Brandt | last post by:
I am using some buttons to hide/show various divs and am changing the style of the button to indicate which button's view is "active". My problem is that for the non-active buttons I want the...
2
by: mjansen.merge.emed | last post by:
Is there a way to override inline within the <bodya style of an element but not do it with a style attribute on the element? I know CSS Inheritance works for some styles, but doesn't appear to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.