Check if a DIV id exists with JQuery
<p>Using Javascript I'm trying to test whether or not a DIV with the id "test_div" exists in the document.</p>

<p>I'm using</p>

<pre><code>if (getElementById("test_div"))
</code></pre>

<p>in the below script to check if the DIV exists in the document. However it does not work. I don't have very much experience with Javascript; but from the research I have done it seems like my problem might have something to do with the nested function.</p>

<p>The script does work if I remove the </p>

<pre><code>if (getElementById("test_div"))
</code></pre>

<p>Does anyone know how to check if a DIV with the id "test_div" exists in the document from within the function as shown below?</p>

<pre><code>&lt;div id="test_div"&gt;&lt;/div&gt;

&lt;script&gt;
function loadInfo(){
var req = new Request({
    method:'get',
    url:'getinfo.php,
    noCache: true,
    onRequest: function(){

        if (getElementById("test_div")) {
            $('test_div').set('html', 'loading data');
        }

    },  
    onComplete:function(responseText, responseHtml){
        if (JSON.decode(responseText) != null){
            var data = JSON.decode(responseText);

            if (getElementById("test_div")) {
                $('test_div').set('html', data['test_div']);
            }

        }   
    },
    onFailure: function(){

        if (getElementById("test_div")) {
            $('test_div').set('html', '-');
        }

    }           
}).send();  
}
window.addEvent('domready', function(){
loadInfo();
});
&lt;/script&gt;
</code></pre>
