I create li
elements dynamically:
<ul>
<li id="1">1</li>
<li id="2">2</li>
<li id="3">3</li>
[...]
</ul>
li_id
is an array value which returns li id (=1,2,3...)
How can I bind different functions to every li
element in code like this:
for (li_id in lids)
{
console.log(li_id);
$(li_id).bind('mouseover', function() {
console.log(li_id);
});
}
The above doesn't work. How to write it properly?
With live()
instead of bind()
it shows the id of the last element of the lids
array, not 1,2,3...[...], like the console.log()
outside the $
statement...