I wrote this code for create menu with `div` tag

**HTML:**

```
<div id="firstMenuList">
            <div id="firstMenu">choose▼</div> 
                <div id="menulist" class="menulist"></div>    
</div>

```

**JavaScript:**

```
<script>
function ccc() {

 var id="firstMenu";

 var ar=new Array("hi","there","hello","world");

 var node=document.createElement("div");

 var parent=document.getElementById("menulist");

 var nodeData="";

 for (var i=0;i<ar.length;i++)
 {
    var node=document.createElement("div");
    node.setAttribute("id",id+""+i);
    node.setAttribute("class","menulist");

    node.setAttribute("onclick","select("+id+""+i+")");
    node.style.top=((i+1)*100)+3+"%";
    node.innerHTML=ar[i];
    parent.appendChild(node);

 }
}

function select(id)
{   
 var p=document.getElementById(id);<-this doesn't work on elements that created dynamically
 p.style.backgroundColor="red";
 var t = p.innerHTML;
}
</script>

```

This code creates the menu, but when I click on the menu items code breaks.
The error is:

> 
> "parent is null"
> 
> 
>