473,395 Members | 1,335 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,395 software developers and data experts.

Javascript DOM tree navigation question

Given this example page;

<HTML>
<HEAD>
<TITLE>test</TITLE>

<BODY>

<DIV ID="test_div">
<P>test paragraph</P>
</DIV>

</BODY>
</HTML>

What is the construction of the DOM element name that is the DIV with
the ID "test_div"?

E.g.

I could go;

var
d;

d = document.getElementById( "test_div" );

But if I didn't have getElementById(), what name would I use to directly
reference the div?

E.g. for a form, I might write;

document.forms["test_form"];

or I might go;

document.images["test_image"].src = "http://www.lala.com/wibble.png";

But what would I use to set say a style attribute on the div?

Note that this is not for IE, so I can't use document.all.
Mar 21 '06 #1
3 1324
Toby Douglass wrote:
Note that this is not for IE, so I can't use document.all.


Also note I want to be DOM0 compatible...fun eh? =-)

I've spent the last couple of hours trying to find a way, but everyone's
been using getElement() for the last couple of years, and before that
it's document.all and Netscape Layers. I actually suspect it's not
possible to directly access div elements via DOM0, although that would
be pretty awful.
Mar 21 '06 #2


Toby Douglass wrote:
<DIV ID="test_div">
<P>test paragraph</P>
</DIV> d = document.getElementById( "test_div" );

But if I didn't have getElementById(), what name would I use to directly
reference the div?


If the div were absolutely or relatively positioned then in Netscape 4
you would find it with
document.layers.test_div
Otherwise in NN4's object model the div is not exposed to script. Nor is
a simple div exposed to script in earlier browsers.

What kind of user agents are you targetting that you can't use
document.getElementById or document.all?
--

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 21 '06 #3
Toby Douglass wrote:
Toby Douglass wrote:
Note that this is not for IE, so I can't use document.all.
Also note I want to be DOM0 compatible...fun eh? =-)


Impossible, see below.
I've spent the last couple of hours trying to find a way, but everyone's
been using getElement() for the last couple of years, and before that
it's document.all and Netscape Layers. I actually suspect it's not
possible to directly access div elements via DOM0, although that would
be pretty awful.


It is. However, a `div' element is only element of the document.layers
collection if it is positioned. And you will not be able to read its
contents, only overwrite it. document.all is more flexible in that regard.

My dhtml.js still supports both proprietary object models:

<URL:http://pointedears.de/scripts/test/dhtml.js>

That said, neither document.all nor document.layers are part of DOM Level 0.
PointedEars
Mar 22 '06 #4

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

Similar topics

4
by: JesusFreak | last post by:
From: us_traveller@yahoo.com (JesusFreak) Newsgroups: microsoft.public.scripting.jscript Subject: toolbar script problem NNTP-Posting-Host: 192.92.126.136 Recently, I downloaded the following...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
3
by: piotrek | last post by:
Hi I would like to ask you a question. Ian creating app. that download from server directory structure ( whole tree ) and those data are placed in proper places into my treeview control. I...
2
by: davidwank | last post by:
Hi. Why is it practical to have the ASP.NET navigation controls based on XML? I would love to just use databinding and then be able to dynamically update the navgiation menu (e.g. for a ...
1
by: Satish.Talyan | last post by:
hi, i want to create a dynamic tree hierarchy in javascript.there are two parts in tree, group & user.when we click on group then users come under that's tree category will be opened.problem is...
0
by: islandfong | last post by:
I am a beginner in ASP.NET. I am trying to use Master page to create the navigation tree. I can create the navigation tree of the header. but how can I created the navigation tree on the left hand...
3
by: designtist | last post by:
Hi, A few weeks ago I found a script at this page for a js navigation menu: http://groups.google.fr/group/comp.lang.javascript/msg/6caa4b5950aae96c It's working fine, but I only have one...
93
by: lorlarz | last post by:
Here, let's see what you JavaScript programmers have got Here is a place to share your large or larger full-blown JavaScript applications: real.comp.lang.js.apps (a new google group) Here is...
2
by: ManidipSengupta | last post by:
Hi, a few (3) questions for the Java experts, and let me know if this is the right forum. It deals with 100% java code (reason for posting here) but manages a Web browser with Javascript. Thanks in...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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...
0
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...

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.