Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-17-2002, 10:06 AM   PM User | #1
Rok
New Coder

 
Join Date: Sep 2002
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Rok is an unknown quantity at this point
why does my code run only in IE?

What's wrong with this code?
When I run JavaScript Console in Mozilla it says:"E has no properties".

The code:




--------------------------------------------------------------------------------------
function razsiri(el, E) {
preventBubble(E);
if (el.open) {
for (var i = 0; i < el.childNodes.length; i++) {
if (el.childNodes[i].nodeType != 3) {
el.childNodes[i].style.display = 'none';}}
el.open = false;
}
else{
for (var i = 0; i < el.childNodes.length; i++) {
if (el.childNodes[i].nodeType != 3) {
el.childNodes[i].style.display = 'block';}}
el.open = true;
}
}

preventBubble = function(E){
if(isIE){
event.cancelBubble=true;
event.returnValue=false;
}else{
if(E.stopPropagation)E.stopPropagation();
else E.preventBubble();
}
};
-------------------------------------------------------------------------------------
Rok is offline   Reply With Quote
Old 09-17-2002, 10:11 AM   PM User | #2
Rok
New Coder

 
Join Date: Sep 2002
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Rok is an unknown quantity at this point
oh, the explanation

The explanation of the code:

It's like Windows Explorer with folders in the left.
I have a "root" <span> (like My Computer ) and several <span>s inside the "My Computer" <span> (they have a display: none), and more <span>s nested inside those.

When you click on a span, the browser checks if the <span> contains (an) element(s). If it does, it sets its display: block and thus shows it.
Rok is offline   Reply With Quote
Old 09-17-2002, 10:24 AM   PM User | #3
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
how did you call razsiri() function? it should be:

<span id="spanID" onclick="razsiri(this, event)">blah blah</span>
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 09-17-2002, 10:31 AM   PM User | #4
Rok
New Coder

 
Join Date: Sep 2002
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Rok is an unknown quantity at this point
Here's the link: link.

all_spans.onclick = function() {razsiri(this, event)}
Rok is offline   Reply With Quote
Old 09-17-2002, 11:30 AM   PM User | #5
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
Quote:
Originally posted by Rok
Here's the link: link.

all_spans.onclick = function() {razsiri(this, event)}
all_spans.onclick = function(event) {razsiri(this, event)}
__________________
jasonkarldavis.com
jkd is offline   Reply With Quote
Old 09-17-2002, 12:33 PM   PM User | #6
Rok
New Coder

 
Join Date: Sep 2002
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Rok is an unknown quantity at this point
Great, it works...

Damn, I really suck with this event thing... I learned JavaScript from a book that did not contained little info about event and on top of it I didn't understand a damn thing because I was just a newbie in JavaScript then. I think I should read through that chapter again. And this time read it thoroughly...

Thanx!
Rok is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:52 AM.


Advertisement
Log in to turn off these ads.