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

Script not working in IE - parentNode problem?

Hi,

I have a script which loops through all <areatags of an imagemap and
changes the visibility of a hidden <div(using MooFX for the
transition). The same script then searches each <divto find the <a
class="close_box"tag which toggles back to invisible.

The script works fine in FF, Opera & Safari, but the second half of the
function - find the <ato toggle visibility again - doesn't work in
IE. Here's the relevant part of the script:

var theCloser =
document.getElementById('rep_holder').getElementsB yTagName('a');
for ( i=0; i < theCloser.length; i++) {
if (theCloser[i].getAttribute('class') == 'close_box') {
theCloser[i].onclick = function() {
var theParent = this.parentNode.parentNode.getAttribute('id');
var theChange = new fx.Opacity(theParent, { duration: 500});
theChange.toggle();
return false;
}
}
}

Can anyone see why this wouldn't work in IE? Is it because of the
parentNodes?

Jul 12 '06 #1
3 5788


pg******@gmail.com wrote:

if (theCloser[i].getAttribute('class') == 'close_box') {
Use the HTML DOM with
if (theCloser[i].className == 'close_box') {
as getAttribute is broken enough in IE to be not compatible with other
browsers.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 12 '06 #2

pg******@gmail.com wrote:
[...]

Martin has answered your problem, but...
theCloser[i].onclick = function() {
var theParent = this.parentNode.parentNode.getAttribute('id');
var theChange = new fx.Opacity(theParent, { duration: 500});
[...]
Can anyone see why this wouldn't work in IE? Is it because of the
parentNodes?
If you are referring to the extra #text nodes that Gecko browsers
insert to retain whitespace in the markup, then no. The extra nodes
are only an issue when navigating down the tree, going upward is fine.

Note however that making your script dependent on the HTML structure is
not a good idea. It may be OK where the structure is invariant, (say
looking for the TR parent of a TD as you know that a TD's parent will
always be a TR) but with an A inside a DIV you can't be sure.

Consider using a while loop to go up the tree until you find the
element you're after.

--
Rob

Jul 12 '06 #3
Many thanks! That was exactly what I was looking for.

I'd read that tip about className before, but it slipped my mind.
Martin Honnen wrote:
pg******@gmail.com wrote:

if (theCloser[i].getAttribute('class') == 'close_box') {

Use the HTML DOM with
if (theCloser[i].className == 'close_box') {
as getAttribute is broken enough in IE to be not compatible with other
browsers.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 13 '06 #4

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

Similar topics

10
by: Chris Martin | last post by:
Background: Our main menu is built using a simple unordered list containing other ULs. There is a table on a page that holds the subnav. Because of certain circumstances, I need to build the subnav...
7
by: Markus Ernst | last post by:
Hello I try to hanlde events centrally for avoiding the need to write four event handler attributes to every link. The task is changing the class name of a link's containing <div> element. After...
2
by: fnsbe | last post by:
Hi everybody, First of all I'm not a java hero but I tried to write my own text editor. Everything works but only when the existing text need to be re-edited the butttons of my editor seem not to...
1
by: stefano | last post by:
Hi, I have a file xml (p.xml) and I use XSLT to trasform p.xml to XHTML. this is the xml file: .... <test label="x"> <itemList> <testItem oknumber="2" > .... </testItem> </itemList>
2
by: Muzzy | last post by:
Hi, I've used information on these newsgroups to build many pages. So I thought that now that I have my script working (something that I've been working on for about a week), I should post it so...
8
by: shyamg | last post by:
plzzz help me............
7
by: buntyindia | last post by:
I have the following scrollable table I have to implemet a functionality that I can select a row in it & display that data in popup window.. Any hints/example or similar available implementation?...
8
Stang02GT
by: Stang02GT | last post by:
I posted a question in the HTML/CSS Forum but i have not received an answer. I have a menu that I am using from http://www.javascriptkit.com . The exact url to the menu i am using is : ...
3
by: jeddiki | last post by:
Hi, I am using this script which is nearly working correctly, but not quite! When a user selects some text from the web-page and copies it, the script is supposed to pick up the current...
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
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
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
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
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,...

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.