How to detect the existence of an element in javascript?
<pre><code>var newHead = '&lt;div id="head'+text+'"&gt;&lt;/div&gt;';
var header = "head"+text;
if (document.getElementById(header) == undefined) {
        //alert(document.getElementById("head"+text));
        $("#result-job").append(newHead);
        var result = '&lt;div id="div' + dataSplit[0] + '"&gt;&lt;input type="radio" checked="checked" class="choosenJob" name="rdb_job" value="' + dataSplit[0] + '" id="' + dataSplit[0] + '" /&gt;&lt;label for="' + dataSplit[0] + '"&gt;' + dataSplit[1] + '&lt;/label&gt;&lt;br /&gt;&lt;/div&gt;';
        $("div#" + header).append(result);
    } else {
        var result = '&lt;div id="div' + dataSplit[0] + '"&gt;&lt;input type="radio" checked="checked" class="choosenJob" name="rdb_job" value="' + dataSplit[0] + '" id="' + dataSplit[0] + '" /&gt;&lt;label for="' + dataSplit[0] + '"&gt;' + dataSplit[1] + '&lt;/label&gt;&lt;br /&gt;&lt;/div&gt;';
        $("div#" + header).append(result);
    }
</code></pre>

<p>Can those script run well ?
I want add some new element(div) in the result div
but my script didnt work</p>

<p>fiddle simulation: <a href="http://jsfiddle.net/86kH4/5/" rel="nofollow">http://jsfiddle.net/86kH4/5/</a></p>
