strange behaviour of getElementById() and .split() method in Javascript
<pre><code>&lt;html&gt;
&lt;script type="text/javascript"&gt;

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";

};


function executeFunc()  {

    var cookieData=document.cookie.split(';');
    for(entry in cookieData)
    {
        createCookie(cookieData[entry],"",-1); //clear the cookie first
    }
    createCookie("node-1","1",365);
    createCookie("node-2","1",365);
    createCookie("node-3","1",365);

    alert("the cookie contains : " + document.cookie);

    var cookie=document.cookie.split(';');

        for(ele in cookie)
        {
            var node=cookie[ele].split('=');


            alert(node[0]);  //this prints the next node correctly
            var nodeId=document.getElementById(node[0]); //for the first 
                     //iteration i get the row in 
                     //nodeId correctly but for the next iterations, i get null, 
                     //althought the row exists. if i type in the row Id manually 
                     //it works, but if i use node[0] then it returns null !! :S
            alert("the node is : " + nodeId);

            alert(document.cookie);



        }


}


&lt;/script&gt;
&lt;body onLoad="executeFunc()"&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr id="node-1"&gt;
    &lt;td&gt;im node 1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr id="node-2"&gt;
    &lt;td&gt;im node 2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr id="node-3"&gt;
    &lt;td&gt;im node 3&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>first of all i dint know how to run the above code on Jsfiddle and then link it to my question. sorry for that!!</p>

<p>In executeFunc() in javascript, i am spliting the cookie entries and extracting the names in "node" variable. then using this name, i get the row object and print it. when it loops for the first time, everything goes as planned but for the next iterations, <code>alert(node[0])</code> prints the next entry in the cookie(i.e node-2) but <code>nodeId=document.getElementById(node[0])</code> returns null. if i change it to <code>nodeId=document.getElementById("node-2")</code> it works fine. i dont knw wat the prblm is..you can test it by just copy pasting it...its the complete code!!
Thanks!!</p>
