473,811 Members | 3,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_bo x"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.getEle mentById('rep_h older').getElem entsByTagName(' a');
for ( i=0; i < theCloser.lengt h; i++) {
if (theCloser[i].getAttribute(' class') == 'close_box') {
theCloser[i].onclick = function() {
var theParent = this.parentNode .parentNode.get Attribute('id') ;
var theChange = new fx.Opacity(theP arent, { duration: 500});
theChange.toggl e();
return false;
}
}
}

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

Jul 12 '06 #1
3 5797


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.get Attribute('id') ;
var theChange = new fx.Opacity(theP arent, { 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
1307
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 dynamically on each page. I wrote this script in about 15 minutes because it was a "scope-creep" kinda thing. Now that I have a bit of time, for education reasons, I want to optimize this thing as much as possible. Notes: DOM is a heaven send...
7
1376
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 lots of googling I came to this: if (document.getElementsByTagName) { a = document.getElementsByTagName("a"); for (var i=1; i<a.length; i++) { var element = a;
2
2471
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 work anymore... This is the main script : <!-- function storeCaret (txtarea) { if (txtarea.createTextRange) {
1
1412
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
3120
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 that it may help others. If posting this script is against the rules in this group then please accept my appologies. I developped this script so that I can add and remove rows in a table in which I have various input fields and I would use the...
8
2955
by: shyamg | last post by:
plzzz help me............
7
6174
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? http://img120.imageshack.us/img120/8209/tableyv4.gif http://www.imaputz.com/cssStuff/bigFourVersion.html# Help
8
1521
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 : http://www.javascriptkit.com/script/script2/csstopmenu.shtml My problem is that the page i placed the menu on, everything on that page is centered and stays underneath the page heading. I have having trouble positioning my menu within the same area as...
3
2145
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 web-page url and create a resource box or credit line that is added to the selected text when the data is pasted. You will see that the meta keywords are used (randomly) as the anchor text
0
9734
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9607
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10395
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10408
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9211
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7673
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4346
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 we have to send another system
2
3874
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3026
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.