Why doesn't this work in IE?

Discussion in 'JavaScript' started by mark_s, Jan 11, 2008.

  1. #1
    Please can someone tell me why this script isn't working in IE7? It works in Firefox and Opera.

    EDIT: When you click 'heading' more content should then show.

    <script type="text/javascript"><!--
    function dsp(loc){
       if(document.getElementById){
          var foc=loc.firstChild;
          foc=loc.firstChild.innerHTML?
             loc.firstChild:
             loc.firstChild.nextSibling;
          foc.innerHTML=foc.innerHTML==''?'':'';
          foc=loc.parentNode.nextSibling.style?
             loc.parentNode.nextSibling:
             loc.parentNode.nextSibling.nextSibling;
          foc.style.display=foc.style.display=='block'?'none':'block';}}  
    
    if(!document.getElementById)
       document.write('<style type="text/css"><!--\n'+
          '.more_content{display:block;}\n'+
          '//--></style>');
    //--></script>
    Code (markup):

     
    mark_s, Jan 11, 2008 IP
  2. wisdomtool

    wisdomtool Moderator Staff

    Messages:
    15,826
    Likes Received:
    1,367
    Best Answers:
    1
    Trophy Points:
    455
    #2
    Are you suppose to see this

    heading

    I saw the same thing in Firefox as well as IE 7. Looks ok for me.
     
    wisdomtool, Jan 11, 2008 IP
  3. mark_s

    mark_s Peon

    Messages:
    497
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes but when you click 'heading' it is meant to expand. Sorry, I didn't explain that earlier.
     
    mark_s, Jan 11, 2008 IP
  4. wisdomtool

    wisdomtool Moderator Staff

    Messages:
    15,826
    Likes Received:
    1,367
    Best Answers:
    1
    Trophy Points:
    455
    #4
    Yeap there is an error, at the bottom toolbar shows error on page for IE 7.
     
    wisdomtool, Jan 11, 2008 IP
  5. mark_s

    mark_s Peon

    Messages:
    497
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yup which is why I'm asking if anyone knows how I can fix it :)
     
    mark_s, Jan 11, 2008 IP
  6. WebGyver

    WebGyver Guest

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    This works in Firefox and in IE7:


    <script type="text/javascript"><!--
    function dsp(loc){
       if(document.getElementById){
          var foc=loc.firstChild;
    
    		 foc=loc.firstChild.innerHTML?
             loc.firstChild:
             loc.firstChild.nextSibling;
    
    //     	    foc.innerHTML=foc.innerHTML==''?'':'';
    
             foc=loc.parentNode.nextSibling.style?
             loc.parentNode.nextSibling:
             loc.parentNode.nextSibling.nextSibling;
          foc.style.display=foc.style.display=='block'?'none':'block';}}
    
    if(!document.getElementById)
       document.write('<style type="text/css"><!--\n'+
          '.more_content{display:block;}\n'+
          '//--></style>');
    //--></script>
    PHP:
     
    WebGyver, Jan 11, 2008 IP
  7. WebGyver

    WebGyver Guest

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Here's an improved version:


    <script type="text/javascript"><!--
    function dsp(loc){
       if(document.getElementById){
          var foc=loc.firstChild;
    
    		 foc=loc.firstChild.innerHTML?
             loc.firstChild:
             loc.firstChild.nextSibling;
    
         	 var th = document.getElementById(loc);
         	 if(th != null){
         	 	th.innerHTML=th.innerHTML==''?'':'';
         	 	// foc.innerHTML=foc.innerHTML==''?'':'';
         	 }
    
             foc=loc.parentNode.nextSibling.style?
             loc.parentNode.nextSibling:
             loc.parentNode.nextSibling.nextSibling;
          foc.style.display=foc.style.display=='block'?'none':'block';}}
    
    if(!document.getElementById)
       document.write('<style type="text/css"><!--\n'+
          '.more_content{display:block;}\n'+
          '//--></style>');
    //--></script>
    PHP:
     
    WebGyver, Jan 11, 2008 IP
  8. mark_s

    mark_s Peon

    Messages:
    497
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #8
    mark_s, Jan 11, 2008 IP
  9. WebGyver

    WebGyver Guest

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Can you show me a test page or something?

    Looking at the link you have at the top of this thread, I can't see a difference between IE and FF.


    However, if I understand you correctly, this might help:

    if(!document.getElementById)
       document.write('<style type="text/css"><!--\n'+
          '.more_content{display:block;overflow:auto;}\n'+
          '//--></style>');
    PHP:
     
    WebGyver, Jan 11, 2008 IP
  10. mark_s

    mark_s Peon

    Messages:
    497
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #10
    With some messing around it seems to go away but thanks for that new code, I'll use it if the problem comes back.

    Can you confirm it loads fine in FF and IE for you now? Do you see the image?

    http://www.murraysworld.com/test.php
     
    mark_s, Jan 11, 2008 IP
  11. WebGyver

    WebGyver Guest

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Seems to work in both browsers.

    Here's an IE screen capture:

    [​IMG]
     
    WebGyver, Jan 11, 2008 IP