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

problems with DOM

I want to save an object of an image in a variable.
I am doing this with the internet explorer with no problems using the following line:
oImage = node.childNodes(0).all["pic"]

Now I wanted to use the W3C-standard and thought I could get my object using this here:
oImage = node.childNodes(0).getElementById("pic")

The node variable is from an xsl file:
....
<div onclick="window.event.cancelBubble = true; clickOnNode(this);"
....

I don´t get it! I´ve tried a lot of variations and searched the net but I didn´t find anything.
Thanks for every little hint on this topic! Greetings,
Tim.
Jul 20 '05 #1
11 4101


Tim Bücker wrote:
I want to save an object of an image in a variable.
I am doing this with the internet explorer with no problems using the following line:
oImage = node.childNodes(0).all["pic"]

Now I wanted to use the W3C-standard and thought I could get my object using this here:
oImage = node.childNodes(0).getElementById("pic")


Use
node.ownerDocument.getElementById("pic")
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
Thanks for the quick answer but unfortunately the problem is not solved.
It is still the same - ignoring the active node always the first one in the
document gets selected (I want to change icons for a menu whether they
are selected or not)!

Is more information needed? Any resources on the web concerning this
topic? More ideas? I am getting more and more desperate...

But thanks again for answering,
Tim.

"Martin Honnen" <ma*******@yahoo.de> schrieb im Newsbeitrag news:3f********@olaf.komtel.net...


Tim Bücker wrote:
I want to save an object of an image in a variable.
I am doing this with the internet explorer with no problems using the following line:
oImage = node.childNodes(0).all["pic"]

Now I wanted to use the W3C-standard and thought I could get my object using this here:
oImage = node.childNodes(0).getElementById("pic")


Use
node.ownerDocument.getElementById("pic")
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #3
VK
"DIV via DOM" doesn't expose getElementById() neither getElementByName()
methods, at least not in IE.

If you really want to keep your life as complicated as possible ;-) then
use something like:
myNode.childNodes(0).getElementsByTagName('IMG')[0].src = newSrc;

To spice it up, you actually can remove first the retrieved image node,
create a new one with another src attribute and insert it back.

Last stupid question: why not use the global document.images[i]
collection? It's totally correct 3W-approved syntacs, if you are worried
about it.

Jul 20 '05 #4
"Tim Bücker" <ti***********@web.de> writes:
I want to save an object of an image in a variable. I am doing this with the internet explorer with no problems using
the following line: oImage = node.childNodes(0).all["pic"]
The "all" property is IE specific. You could use:
oImage = node.firstChild.getElementsByTagName("*")["pic"];
The getElementsByTagName("*") creates a collection equivalent to the
"all" collection.

I would just do
oImage = document.images["pic"];
If "pic" is the ID of the image, then it must be unique in the
document.
Now I wanted to use the W3C-standard and thought I could get my object using this here:
oImage = node.childNodes(0).getElementById("pic")
getElementById only exists on the document object. There is no need for
more than one, since Id's must be unique in the document.

If the node isn't from this document, then you can find the appropriate
document as: node.ownerDocument
(Same goes for document.images above).
The node variable is from an xsl file:
...
<div onclick="window.event.cancelBubble = true; clickOnNode(this);"


"window.event" is IE specific, and so is "cancelBubble".
In onclick attribute values, the variable "event" points directly to
the event (in other browsers it is a local variable, in IE it is global).

The W3C version would be:
<div onclick="event.stopPropagation();clickOnNode(this) ;">
Since IE doesn't support that, you'll have to do both:
<div onclick="if(event.stopPropagation){event.stopPropa gation();}
else{event.cancelBubble = true;}; clickOnNode(this);">

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
Thanks a lot for all the interesting information!
I will work myself through each of your proposals and see if they work in my case.
Unfortunately (for example) "pic" is not unique; as I use a xsl file like this:

<xsl:template match="node">
....
<img border="0" id="pic">
<xsl:attribute name="src">
<xsl:value-of select="testPic" />
</xsl:attribute>
</img>
....
</xsl:template>

But anyway thanks to everyone who tried to help me!
Thanks a lot.

Greetings,
Tim.
Jul 20 '05 #6
Unfortunately I am always getting an error message in the following line:
oImage = myNode.firstChild.getElementsByTagName("*")["pic"];
Although getElementsByTagName returns an object. So here is nothing wrong I think.

Event thread: onclick
Error:
name: TypeError
message: Statement on line 71: Expression did not evaluate to a function object: myNode.firstChild.getElementsByTagName

Any ideas? Again everything is working great using the IE.

Thanks again for answering,
Tim.
Jul 20 '05 #7
Using Opera getElementsByTagName does NOT return an object!
[ myNode.firstChild.getElementsByTagName("*") ]

"Tim Bücker" <ti***********@web.de> schrieb im Newsbeitrag news:bp***********@news.uni-koblenz.de...
Unfortunately I am always getting an error message in the following line:
oImage = myNode.firstChild.getElementsByTagName("*")["pic"];
Although getElementsByTagName returns an object. So here is nothing wrong I think.

Event thread: onclick
Error:
name: TypeError
message: Statement on line 71: Expression did not evaluate to a function object: myNode.firstChild.getElementsByTagName

Any ideas? Again everything is working great using the IE.

Thanks again for answering,
Tim.

Jul 20 '05 #8
"Tim Bücker" <ti***********@web.de> writes:
Using Opera getElementsByTagName does NOT return an object!
[ myNode.firstChild.getElementsByTagName("*") ]


Are you sure the first child is not a text node?
Remember, IE removes empty (all whitespace) text nodes from the document
tree, Mozilla and Opera doesn't.

Drop the ".firstChild", and it will probably work.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #9
Thanks a lot! That was the magic answer - at least my menu is now working on IE _and_ Opera. Unfortunately Netscape is still a
problem...

If I am honest, I did not really understand the thing with the text nodes.
Do you perhaps know a good internet resource about that kind of cross-browser compatibility?

Again - thanks a lot!
Greetings,
Tim.

"Lasse Reichstein Nielsen" <lr*@hotpop.com> schrieb im Newsbeitrag news:zn**********@hotpop.com...
"Tim Bücker" <ti***********@web.de> writes:
Using Opera getElementsByTagName does NOT return an object!
[ myNode.firstChild.getElementsByTagName("*") ]


Are you sure the first child is not a text node?
Remember, IE removes empty (all whitespace) text nodes from the document
tree, Mozilla and Opera doesn't.

Drop the ".firstChild", and it will probably work.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #10
"Tim Bücker" <ti***********@web.de> writes:

(Please don't top post)
Thanks a lot! That was the magic answer - at least my menu is now
working on IE _and_ Opera. Unfortunately Netscape is still a
problem...
Do tell, what is the problem :)
If I am honest, I did not really understand the thing with the text
nodes. Do you perhaps know a good internet resource about that kind
of cross-browser compatibility?


Not really, no, sorry.

About the text nodes:

The DOM (Document Object Model) uses different kinds of DOM "Nodes"
(objects with some basic properties and methods) to represent
different parts of a document. There are, among others, Document
Nodes, Comment Nodes, Element Nodes and Text Nodes. The different
types have more specialized properties and methods than the
abstract Node class.

The code
<div>foo<span>bar</span>baz</div>
generates one Element Node for the div element. It has three child nodes:
- One text node containing the text "foo".
- One Element node for the span element. It has a text node as child,
containing "bar".
- One text node containing the text "baz".

The difference between browsers here is when two tags appear next to each other
with only whitespace between, e.g.:
<div>
<span>foo</span>
</div>

Between "<div>" and "<span>" is one newline and two spaces. In Mozilla
and Opera, that gives rise to a Text Node with those three characters.
IE doesn't generate Text Nodes for strings containing only whitespace.

Your problem was that getElementsByTagName is a method of Element Nodes,
not Text Nodes, and the first child element of your node was a text node
in Mozilla/Opera and an element node in IE.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #11
"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote:
(Please don't top post)
Sorry for that!
Thanks a lot! That was the magic answer - at least my menu is now
working on IE _and_ Opera. Unfortunately Netscape is still a
problem...


Do tell, what is the problem :)


I think the problem is a bit hard to explain - that was the reason why I didn´t ask you.
But I´ll give it a try:

I am trying to develop a dynamic menu using xml for the data and xsl for the design.
As usual you have a + sign and a - sign in front of each node that has children.
Thanks to your help I have now managed to get it run on IE and Opera and the expansion
of nodes also works using Netscape 7 (the only version I am trying at the moment) the
BIG problem is that the collapsing is absolutely not working using NS! The main problem
at the moment is that clicking on a - sign not only all the children are disappearing but also
the parent node so that it is now possible to create a totally blank page clicking through the
menu.

My collapse function looks like this:

function collapse(myNode)
{
var i, oImage
myNode.getElementsByTagName('*')["pic"].src = myNode.getAttribute("pictureClosed");

for (i=0; i<myNode.childNodes.length; i++)
{
// to get rid of the empty text nodes
if (myNode.childNodes[i].style)
{
if (myNode.tagName == "DIV")
{
if (myNode.id != "root")
myNode.childNodes[i].style.display = "none"
collapse(myNode.childNodes[i])
}
}
}
myNode.setAttribute("open", "false");

/* // This code here works using IE and Opera (debug version)
for (i=0; i<myNode.childNodes.length; i++)
{
if (myNode.childNodes(i).tagName == "DIV")
{
if (myNode.id != "root")
myNode.childNodes(i).style.display = "none"
collapse(myNode.childNodes(i))
}
}
*/
}

I hope I could make myself clear at this time of day.
If you need more information I would love to send it to you ;-)
About the text nodes:

Thanks a lot for the information about text nodes!

Thank you for taking you time!
Greetings,
Tim.
Jul 20 '05 #12

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

Similar topics

0
by: Jerome Lefebvre | last post by:
Hello, Hope this will interest a few. I been working with a friend on the problems given out during the "International Collegiate Programming Contest" (ICPC) http://icpc.baylor.edu/icpc/ ....
14
by: Jim Hubbard | last post by:
Are you up to speed on the difficulties in using the 1.1 .Net framework? Not if you are unaware of the 1,596 issues listed at KBAlertz (http://www.kbalertz.com/technology_3.aspx). If you are...
1
by: 3f | last post by:
Hello; We have made a web application that people can download from our web site and installed on: Windows XP Windows 2000 Professional Windows 2003 Server Windows 2000 Server
5
by: Corky | last post by:
This works: db2 SELECT DISTINCT PROBLEM_OBJECTS.PROBLEM_ID FROM PROBLEM_OBJECTS INNER JOIN PROBLEMS ON PROBLEM_OBJECTS.PROBLEM_ID = PROBLEMS.PROBLEM_ID WHERE INTEGER(DAYS(CURRENT DATE) -...
2
by: Ellen Graves | last post by:
I am having a lot of problems with DB2 8.3.1 on RH Linux AS2.1. Installing and running stored procedures is problematic. Stored procedures I have used for years on V7 on WinNT are now failing...
19
by: Jim | last post by:
I have spent the past few weeks designing a database for my company. The problem is I have started running into what I believe are stack overflow problems. There are two tab controls on the form...
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
19
by: Dales | last post by:
I have a custom control that builds what we refer to as "Formlets" around some content in a page. These are basically content "wrapper" sections that are tables that have a colored header and...
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
0
by: Sergistm | last post by:
Hello World, :D I have a problem that it is making me crazy, I hope you can help me. I'm trying to execute a .exe file with the Procces.Start, and there is no problem when the file is on my...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.