473,395 Members | 1,488 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.

className (ie vs moz)

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

In Firefox this works:
document.getElementById('foo').parentNode.classNam e

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 11168
tg****@gmail.com wrote:
I am trying to retrieve a the class name of a parentnode.

In Firefox this works:
document.getElementById('foo').parentNode.classNam e

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"><span id="foo">foo</span></div>

<script type="text/javascript">
alert(document.getElementById('foo').parentNode.cl assName);
</script>

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

In Firefox this works:
document.getElementById('foo').parentNode.classNam e

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 getAncestorClass(node)
{
var cN;
while (node = node.parentNode)
if (cN = node.className)
return cN;
return null;
}

getAncestorClass(document.getElementById('foo'));

Jul 23 '05 #3
tg****@gmail.com wrote:
In Firefox this works:
document.getElementById('foo').parentNode.classNam e
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').parentNode.ta gName)
or
alert(document.getElementById('foo').parentNode.ou terHTML)

to see what the browser is really pointing to.

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


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

In Firefox this works:
document.getElementById('foo').parentNode.classNam e

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.getElementById 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.com 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.com 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)">click 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('nextSibling is : ' + ((s)? s.nodeName : 'nothing' ));
}
</script>
<ul>
<li onclick="doClick(this)">click me</li>
<li onclick="doClick(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
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...
1
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 ...
1
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 {...
1
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...
16
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...
2
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...
9
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...
4
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...
0
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
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
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?
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
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...
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...

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.