473,698 Members | 2,185 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 11185
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
2848
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
3025
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
5665
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
1788
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
2866
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
1921
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
2094
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
2939
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
1642
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
9152
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...
0
7708
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
6515
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
5857
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
4358
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4612
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3037
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
2320
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1995
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.