Friday, April 8, 2011

Javascript in IE vs Firefox

The following script works fine in IE7 but fails to execute in Firefox 3. The div tag which was display: none; shows in IE but never in FF. I am not a client / javascript guy... thanks.

<script type="text/javascript">
//<![CDATA[
document.getElementById("Fred1_Panel").style.setAttribute("display","inline");//]]>

</script>
From stackoverflow
  • This will work in both browsers:

    document.getElementById("Fred1_Panel").style.display = 'inline';
    
    Andrew Robinson : thanks. both fix my issue. gave the answer to the guy with the fewer points. sure wish I could assign "2" correct answers.
    Triptych : @Andrew. Just FYI, typically you would accept the first answer if two are the same. Glad to help out.
  • try this:

    document.getElementById("Fred1_Panel").style.display = '';
    

    OR

    document.getElementById("Fred1_Panel").style.display = 'inline';
    
  • In FF, starting with either Tools | Error Console, or FireBug's console is a good way to see what errors are occurring.

  • This code should work:

    document.getElementById("Fred1_Panel").style.display = "inline";
    

    In general if you encounter problems in Firefox you can easily discover the exact problem (and maybe find out the solution) using Firebug plugin or simply seeing at the Error console.

0 comments:

Post a Comment