Javscript Issue in Firefox

3 replies

I am trying to add some simple javascript code to one my webpages as I need to hide a couple of divs on page load. Firefox does not seem to accept this code but all other browsers do. I have a similar issue with Firefox in the past and found a way around it. I would highly appreciate it if someone could shed some light on this issue so that I could tackle this Firefox problem I have once and for all.

Thanks in advance!


Firefox does not hide the divs and gives me the following errors:

script2 is not defined
script 22 is not defined


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">

<script type="text/javascript">

function initiate(){


script2.style.display = "none";
script22.style.display = "none";



<body onload="initiate();">

<div id="script2">

<div id="script22">

#firefox #issue #javscript
  • Profile picture of the author imarketstuff
    hey there,

    why don't you force them to be "hidden" using css, by associating the divs with a class.

    that seems to serve your purpose with this function.

    you should also note that not all the browser use (display,visibility) the same.

    {{ DiscussionBoard.errors[1893860].message }}
  • Profile picture of the author osegoly
    I'll try it out.
    {{ DiscussionBoard.errors[1894119].message }}
  • Profile picture of the author Jinil Sung
    You need to use getElementbyId function to access style attribute in DOM3.

    function initiate() {
    document.getElementById('script2').style.display = 'none';
    document.getElementById('script22').style.display = 'none';
    {{ DiscussionBoard.errors[2257497].message }}

Trending Topics