show/hide div not fully working in IE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ryrocks
    New Member
    • May 2008
    • 19

    show/hide div not fully working in IE

    Hi,
    Im making a 'contact us' page. The user click on the div, this then reveals another larger div displaying more information giving the effect of the box expanding or dropping down.

    I have 3 starting divs on my page, each one expanding onclick. The show/hide elemant works fine. There is one slight problem... I want the user to be able to click anywhere inside the starting div in order for the hidden div to be revealed. This is ok for the first set of divs, but you can only click on the text or border for the second and third div sets. I can't figure out for the life of me why the second and third divs aren't allowing the onclick anywhere inside the div. The HTML and CSS are identical for all 3 so i guess it must be a JS issue.
    The whole thing works fine in Firefox just not IE!

    Here's an online example:


    Here's my HTML:

    [HTML]<div id="contact_us_ conatiner">

    <div id="gallery">

    <!-- TAB 1 -->
    <div class="off" title="tab1"><p >UK Orders</p></div>
    <div id="tab1" class="hide">
    <p>Question 1</p>
    </div>

    <!-- TAB 2 -->
    <div class="off" title="tab2"><p >Product Technical Support</p></div>
    <div id="tab2" class="hide">
    <p>Question 2</p>
    </div>

    <!-- TAB 3 -->
    <div class="off" title="tab3"><p >Regional Sales Specialists</p></div>
    <div id="tab3" class="hide">
    <p>content 3</p>
    </div>

    </div><!-- END - gallery div -->
    </div><!-- END - contact_us_cona tiner -->
    [/HTML]
    CSS:
    [CODE=css]* {
    padding:0;
    margin:0;
    }
    #contact_us_con atiner {
    width:727px;
    position:relati ve;
    float:left;
    margin-left:30px;
    margin-top:30px;
    }
    #gallery {
    font:11px arial,sans-serif;
    width:700px;
    height:33px;
    line-height:15px;
    position:relati ve;
    float:left;
    z-index:200;
    }
    #gallery div.off {
    width:600px;
    color:#000;
    float:left;
    border:1px solid #ddd;
    cursor:pointer;
    text-align:center;
    height:33px;
    line-height:33px;
    position:relati ve;
    z-index:120;
    margin-bottom:20px;
    }
    #gallery div.on {
    width:600px;
    color:#c00;
    float:left;
    border:1px solid #000;
    border-bottom:0;
    cursor:pointer;
    text-align:center;
    height:33px;
    line-height:32px;
    position:relati ve;
    z-index:100;
    }
    div.hide {
    display:none;
    width:0;
    overflow:hidden ;
    }
    div.show {
    width:600px;
    height:115px;
    margin-top:0;
    border:1px solid #000;
    border-top:0;
    position:relati ve;
    z-index:50;
    font-family:Arial, Helvetica, sans-serif;
    font-size:12px;
    float:left;
    margin-bottom:20px;
    }
    .clear {clear:both;}
    [/CODE]
    JS:
    [CODE=javascript]onload = function() {
    var e, i = 0;
    while (e = document.getEle mentById('galle ry').getElement sByTagName ('DIV') [i++]) {
    if (e.className == 'on' ¦¦ e.className == 'off') {
    e.onclick = function () {
    var getEls = document.getEle mentsByTagName( 'DIV');
    for (var z=0; z<getEls.length ; z++) {
    getEls[z].className=getE ls[z].className.repl ace('show', 'hide');
    getEls[z].className=getE ls[z].className.repl ace('on', 'off');
    }
    this.className = 'on';
    var max = this.getAttribu te('title');
    document.getEle mentById(max).c lassName = "show";
    }
    }
    }

    }[/CODE]

    Any help would be MUCH appreciated!
    Thanks in advance

    Ryan
    Last edited by acoder; May 28 '08, 10:07 AM. Reason: Added [code] tags
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Working fine in IE, Fx, Opera and Safari...

    What's not happening according to you?

    Comment

    • ryrocks
      New Member
      • May 2008
      • 19

      #3
      in IE you have to click on the text inside the second and third bars (product technical support and Regional sales specialists)
      I want the user to be able to click anywhere inside the bars, like with the top bar.

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        That's what is happening with my IE. I click on either of the bars (not text), it opens the div. Exactly like what happens in Fx, Op and Sf.

        I'm using IE6.

        Comment

        • hsriat
          Recognized Expert Top Contributor
          • Jan 2008
          • 1653

          #5
          Originally posted by hsriat
          That's what is happening with my IE. I click on either of the bars (not text), it opens the div. Exactly like what happens in Fx, Op and Sf.

          I'm using IE6.
          May be its working fine with my IE as I keep on cursing it. You try the same trick.
          (j/k)

          Comment

          • ryrocks
            New Member
            • May 2008
            • 19

            #6
            well im glad it works in IE6! I've been unable to test it with that. However IE7 is still proving to be a problem!

            Comment

            • hsriat
              Recognized Expert Top Contributor
              • Jan 2008
              • 1653

              #7
              Originally posted by ryrocks
              well im glad it works in IE6! I've been unable to test it with that. However IE7 is still proving to be a problem!
              Oh.. so its an IE7 thing...

              You are assigning function to the click event of the div: e.onclick = function ()
              Then how can it work only when text is clicked and not the empty part of the div?

              I guess there's some problem either with some other part of the code, or IE7 is confused.

              Comment

              • ryrocks
                New Member
                • May 2008
                • 19

                #8
                Originally posted by hsriat
                Oh.. so its an IE7 thing...

                You are assigning function to the click event of the div: e.onclick = function ()
                Then how can it work only when text is clicked and not the empty part of the div?

                I guess there's some problem either with some other part of the code, or IE7 is confused.
                Exactly! I've not idea why it only works when you click the text or the border. And why does it work fine on the top bar? Yes I think IE7 is getting confused... like me!

                Comment

                • hsriat
                  Recognized Expert Top Contributor
                  • Jan 2008
                  • 1653

                  #9
                  Originally posted by ryrocks
                  Exactly! I've not idea why it only works when you click the text or the border. And why does it work fine on the top bar? Yes I think IE7 is getting confused... like me!
                  See if this works (though I could not guess what was the problem with IE7)[code=javascript]window.onload = function() {
                  var e, i = 0;
                  while (!!(e = document.getEle mentById('galle ry').getElement sByTagName ('div') [i++]))
                  if (e.title.match(/^tab/))
                  e.onclick = function () {

                  var getEls = document.getEle mentsByTagName( 'div');
                  for (var z=0; z<getEls.length ; z++) {
                  if (getEls[z].id.match(/^tab/)) getEls[z].className = getEls[z].id == this.title ? "show" : "hide";
                  if (getEls[z].title.match(/^tab/)) getEls[z].className = getEls[z] == this ? "on" : "off";
                  }
                  }
                  }[/code]

                  Comment

                  • ryrocks
                    New Member
                    • May 2008
                    • 19

                    #10
                    Thanks for trying but that JS broke it:
                    http://testsite.fisher .co.uk/2008_Redesign/contact_us/contact_us_TEST 2.html

                    Comment

                    • ryrocks
                      New Member
                      • May 2008
                      • 19

                      #11
                      original version:
                      http://testsite.fisher .co.uk/2008_Redesign/contact_us/contact_us_TEST 3.html

                      Comment

                      • hsriat
                        Recognized Expert Top Contributor
                        • Jan 2008
                        • 1653

                        #12
                        Lol!...

                        Could not open your page though, but if replaced in your old code, it works perfectly fine, on all browsers.

                        Oh... may be ... you copied that space in TagName. Remove it. It was an editor's error.

                        Click on reply button on my last past and copy code, instead of copying as it is.

                        Comment

                        • ryrocks
                          New Member
                          • May 2008
                          • 19

                          #13
                          I've remove my JS code and replaced it entirely with your code:
                          [CODE=javascript]window.onload = function() {
                          var e, i = 0;
                          while (!!(e = document.getEle mentById('galle ry').getElement sByTagName ('div') [i++]))
                          if (e.title.match(/^tab/))
                          e.onclick = function () {

                          var getEls = document.getEle mentsByTagName( 'div');
                          for (var z=0; z<getEls.length ; z++) {
                          if (getEls[z].id.match(/^tab/)) getEls[z].className = getEls[z].id == this.title ? "show" : "hide";
                          if (getEls[z].title.match(/^tab/)) getEls[z].className = getEls[z] == this ? "on" : "off";
                          }
                          }
                          }[/CODE]

                          I have the same original problem:


                          We're almost there! I can feel it!
                          Last edited by gits; May 28 '08, 02:39 PM. Reason: added code tags

                          Comment

                          • hsriat
                            Recognized Expert Top Contributor
                            • Jan 2008
                            • 1653

                            #14
                            I'll be honest. I've no idea what's causing this incompatibility in IE7.

                            My Firebug says theres' no error, nor there's any warning!
                            My Web Developer tool bar (Fx) says there's no error, no warning... even in the strict mode.
                            IE6's Developer bar says there's no error, nor any warning!

                            So what can it be?

                            Last thing I can suggest it to add a function on onload event of the body
                            <body onload ="init()">

                            And name that function as init()

                            Comment

                            • ryrocks
                              New Member
                              • May 2008
                              • 19

                              #15
                              nope that didn't work :-(
                              Thanks for all your help

                              Comment

                              Working...