# WTF Javascript

**URL:** <https://forum.kirupa.com/t/wtf-javascript/246872>\
**Category:** web dev\
**Created:** [December 15, 2007, 6:54pm UTC](https://forum.kirupa.com/t/wtf-javascript/246872 "2007-12-15T18:54:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevisazombie](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/kevisazombie/32/3903_2.png) [@kevisazombie](https://forum.kirupa.com/u/kevisazombie)\
**Post date:** [December 15, 2007, 6:54pm UTC](https://forum.kirupa.com/t/wtf-javascript/246872/1 "2007-12-15T18:54:18Z")

</div>

Hi everyone,

I got a javascript problem. I know what is happening but I need some explanation.

I have a function I call when the page is loaded. It sets a variable named content to document.getElementById(‘content’);. I know i have seen this done before but it seems to be the problem. When i set the code up like this. It works in FF but not IE or safari.

```auto
function pageLoaded(){
content = document.getElementById('content'); //get the content section
    buildGallery();
}

///function builds the gallery page
function buildGallery(){
    function stampHeaders(){//make the header images
        var urls = new Array("images/web.gif", "images/print.gif", "images/mm.gif");
        for(var i=0; i<3; i++){
            newitem = document.createElement('img');
            newitem.src=urls*;
            newitem.className="title";
            tempElements.push(newitem);
            content.appendChild(newitem);
        }
        
    };//closes stamp headers
    stampHeaders();
}

```

When I drop the content variable and just get the element in other functions it works in all three. So apparently you cannot assign getElementById to variables?

```auto
function pageLoaded(){
    buildGallery();
}

///function builds the gallery page
function buildGallery(){
    function stampHeaders(){//make the header images
        var urls = new Array("images/web.gif", "images/print.gif", "images/mm.gif");
        for(var i=0; i<3; i++){
            newitem = document.createElement('img');
            newitem.src=urls*;
            newitem.className="title";
            tempElements.push(newitem);
           document.getElementById('content').appendChild(newitem);
        }
        
    };//closes stamp headers
    stampHeaders();
}

```
