# Javascript Variable scope help

**URL:** <https://forum.kirupa.com/t/javascript-variable-scope-help/245794>\
**Category:** web dev\
**Created:** [December 4, 2007, 6:35am UTC](https://forum.kirupa.com/t/javascript-variable-scope-help/245794 "2007-12-04T06:35:38Z")\
**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 4, 2007, 6:35am UTC](https://forum.kirupa.com/t/javascript-variable-scope-help/245794/1 "2007-12-04T06:35:38Z")

</div>

Hi all, I have a function that dynamically adds some LI elements to a UL node the problem I am having is passing a onmouseover and onmouseout function to the LIs. I have the over and out functions declared before the list is populated and I have them statically attached to a differnt list and are working. When trying to attach them in the listimages() function its like they are not being passed through. any help is much appreciated.

```auto
function over(obj){
obj.style.backgroundColor="#000066";
obj.style.fontWeight="bold";
document.body.style.cursor = "pointer";
};

function out(obj){
obj.style.backgroundColor="#006699";
obj.style.fontWeight="normal";
document.body.style.cursor="default";
};

function listimages(imagecount){
var Parent = document.getElementById('images');
 iteration add a new LI with the link info
for(i=0; i<imagecount; i++){
var count = i+1;
newitem= new String("NewLi"+count);
newitem = document.createElement("LI");
newitem.innerHTML = "<p>Image "+count+"</p>";
newitem.onmouseover=over(this);
newitem.onmouseout=out(this);
Parent.appendChild(newitem);
}
};

```
