473,604 Members | 2,483 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

className (ie vs moz)

I am trying to retrieve a the class name of a parentnode.

In Firefox this works:
document.getEle mentById('foo') .parentNode.cla ssName

returns the class name of the parent element. In IE it doesnt work.

What is the correct syntax for IE?

Any help is much appreciated.
Thx.

Jul 23 '05 #1
8 11178
tg****@gmail.co m wrote:
I am trying to retrieve a the class name of a parentnode.

In Firefox this works:
document.getEle mentById('foo') .parentNode.cla ssName

returns the class name of the parent element. In IE it doesnt work.

What is the correct syntax for IE?


Can't tell what your issue is. The following works for me in IE 6
and Firefox:

<div class="blah"><s pan id="foo">foo</span></div>

<script type="text/javascript">
alert(document. getElementById( 'foo').parentNo de.className);
</script>

--
Rob
Jul 23 '05 #2
tgh...@gmail.co m wrote:
I am trying to retrieve a the class name of a parentnode.

In Firefox this works:
document.getEle mentById('foo') .parentNode.cla ssName

returns the class name of the parent element. In IE it doesnt work.

What is the correct syntax for IE?

Any help is much appreciated.
Thx.


function getAncestorClas s(node)
{
var cN;
while (node = node.parentNode )
if (cN = node.className)
return cN;
return null;
}

getAncestorClas s(document.getE lementById('foo '));

Jul 23 '05 #3
tg****@gmail.co m wrote:
In Firefox this works:
document.getEle mentById('foo') .parentNode.cla ssName
returns the class name of the parent element. In IE it doesnt work.


Most likely, the 'parentNode' of the element is not the same in each
browser.

Try
alert(document. getElementById( 'foo').parentNo de.tagName)
or
alert(document. getElementById( 'foo').parentNo de.outerHTML)

to see what the browser is really pointing to.

--
Matt Kruse
http://www.JavascriptToolbox.com
Jul 23 '05 #4


tg****@gmail.co m wrote:
I am trying to retrieve a the class name of a parentnode.

In Firefox this works:
document.getEle mentById('foo') .parentNode.cla ssName

returns the class name of the parent element. In IE it doesnt work.


Element nodes have a className property in IE 4 and later, and nodes
have a parentNode property in IE 5 and later. document.getEle mentById is
supported in IE 5 and later too so your expression should work with IE 5
and later.
When you say "it doesn't work in IE" what exactly happens, do you get a
script error, if so which one exactly?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #5
thanks for the replies

your right it should work but the value is nothing. like null. I dont
even get undefined but just blank.

I should say I am using the createElement to create the nodes and use
..className = "foo" to set the class

Displays properly but i cannot retrieve the value. strange.

Jul 23 '05 #6
Matt,

You were exacly right. IE has a different parentNode than Firefox.
What a POS - I am really starting to hate javascript because of these
issues.

Thx!

Jul 23 '05 #7
tg****@gmail.co m wrote:
You were exacly right. IE has a different parentNode than Firefox.
What a POS - I am really starting to hate javascript because of these
issues.


Don't hate javascript - it's just the language you're using to access the
browser's DOM.
DOMs can be different. You just have to program appropriately.

If you have an <INPUT> and you expect its parent to be a <TD>, don't rely on
that. Instead, walk up the parentNode chain and stop when you get to a <TD>
element. That way, you won't be dependent on a particular browser's decision
to insert assumed objects or rearrange when you didn't expect it to.

--
Matt Kruse
http://www.JavascriptToolbox.com
Jul 23 '05 #8
tg****@gmail.co m wrote:
Matt,

You were exacly right. IE has a different parentNode than Firefox.
What a POS - I am really starting to hate javascript because of these
issues.


Don't blame JavaScript, it is just a scripting language - your issue
is with the different way various browsers implement the DOM.

It is often risky to depend on parentNode/childNode relationships and
frequently search or iterative techniques are required to ensure the
'correct' descendant/ancestor is recognised, e.g.

<table>
<tr>
<td onclick="alert( this.parentNode .parentNode)">c lick me</td>
</tr>
</table>

Will report 'TBODY', not 'TABLE'. If the table was the target, it
may be better to use a function that goes up the parents until the
table is found.

Try this in Firefox and then IE:

<script type="text/javascript">
function doClick(x){
var s = x.nextSibling;
alert('nextSibl ing is : ' + ((s)? s.nodeName : 'nothing' ));
}
</script>
<ul>
<li onclick="doClic k(this)">click me</li>
<li onclick="doClic k(this)">click me</li>
</ul>
Try posting a bit of the HTML you are having trouble with.

--
Rob
Jul 23 '05 #9

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

Similar topics

7
2845
by: Joshua Beall | last post by:
Hi All, I have been trying to dynamically call a static member function, as follows: $className = 'MyClass'; $methodName = 'MyMethod' $result = $className::$methodName(); However, I get a parse error when I do this:
1
3023
by: Pietro | last post by:
Hi at all, I teach into a teachnical school and many boys must to know best CSS. I have two problems: 1)Making tables we'ld want make the cells with round angles. Therefore we apply -moz-border-radius-topleft ecc...... But it work only with Netscape 6 or more. Is there the mean to do to work with MSIE? 2)What is the best CSS book?
1
5662
by: Peter King | last post by:
if you assign multiple classes in order to keep your classes generic e.g ..classA { position.absolute; left:5 top:5 height:200 width:800 } ..classB { background-color: red} ..classC { background-color: green} <div id="div1" class="classA classB" ... but then want to dynamically assign a new class
1
1785
by: Marek Mänd | last post by:
<div style="border:1px solid red;-moz-border-radius:10px"> <div style="margin:0px;padding:0px;background:white;">this is titlebar for my box</div> This is content for my box </div> Is there any hope the round borders can be fooled to show up?
16
2848
by: Java script Dude | last post by:
To all Mozilla JS Guru's (IE dudes welcome), I have spent the last three years developing complex DHTML applications that must work in IE 5.5sp2+ but I use Mozilla 1.3+** to do all my development. I have build some cross browser debuggers so my users can send me verbose debug dumps. I have some success but have come to a roadblock with the basic underlying JavaScript models. The only way to get a complete stack in IE is to use the...
2
1914
by: bmgz | last post by:
I have written a script that highlights a table row when the appropriate checkbox is checked. Using element.style is a bit messy and doesn't really fulfil my needs.. I want to just be able to use className, but when I uncheck a row I am having difficulty restoring the original (when the page loaded) className, I need to do this because the rows have different styles Is their any other way to access the original className of an element?
9
2091
by: VidTheKid | last post by:
Hello everybody. I just became the webmaster of an organization who wants a marquee on the front page. I don't have problems using a marquee sensibly. I actually have some structured content inside the marquee (headings and paragraphs) and there's some CSS to set all those things to display:inline. So, on the screen, this does exactly what I want it to in IE and Firefox, and theoretically any browser that doesn't support marquees...
4
2936
by: Aaron Gray | last post by:
Hi, I want an "isZZZ" variable that I can use to generate "display: -moz-inline-box;" rather than "display: inline-block;" but in DOM. For this I need to know what version of Mozilla this "feature" was added and also how to detect Mozilla as a userAgent. Alternatively is there an alternative to "display: -moz-inline-box" for sticking two tables side by side ?
0
1640
by: gentsquash | last post by:
My CSS does not validate at http://jigsaw.w3.org/css-validator/ Attempting to validate, for example, my http://www.math.ufl.edu/~squash/course.advcal.2008t.html produces (lightly edited) /--------------------------------------------------------\
0
7997
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
7929
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
8419
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8065
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
8280
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5882
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...
0
5441
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3955
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1526
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.