Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Rok
    Rok is offline
    New Coder
    Join Date
    Sep 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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();
    }
    };
    -------------------------------------------------------------------------------------

  • #2
    Rok
    Rok is offline
    New Coder
    Join Date
    Sep 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 251 Times in 247 Posts
    how did you call razsiri() function? it should be:

    <span id="spanID" onclick="razsiri(this, event)">blah blah</span>

  • #4
    Rok
    Rok is offline
    New Coder
    Join Date
    Sep 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's the link: link.

    all_spans.onclick = function() {razsiri(this, event)}

  • #5
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Originally posted by Rok
    Here's the link: link.

    all_spans.onclick = function() {razsiri(this, event)}
    all_spans.onclick = function(event) {razsiri(this, event)}

  • #6
    Rok
    Rok is offline
    New Coder
    Join Date
    Sep 2002
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •