L
lala4life
My problem is that i have an unorderd list generated at runtime by a
recursive function
<UL>
<LI class="li_dir">Lo ultimo en Juegos
<UL>
<LI class="li_dir">Clasicos</LI>
<LI class="li_dir">Novedades</LI>
</UL>
</LI>
</UL>
<script type="text/javascript">
var mn = new GetLiveMenus(); // calling the js
</script>
..li_dir
{
vertical-align: middle;
margin: 2px;
border-style: hidden;
list-style-type: none;
list-style-image: url(/images/folder.gif);
list-style-position: outside;
}
i need to set click, mouseover and mouseout over each "LI" element
to do some task like highlight the desire element and send some
parameter with post. i program a js to do this but when assign the
events to each "LI" it always set the last "LI", following the
example if i put the mouse over the first LI (<LI class="li_dir">Lo
ultimo en Juegos ) highlight the last LI (<LI
class="li_dir">Novedades</LI>), could someone give me some hint about
this issue.
snippet of the code
// constructor
function GetLiveMenus(){
this.nodelist = document.getElementsByTagName("LI");
for (var i = 0; i < this.nodelist.length; i++ ){
var node = this.nodelist;
divNameDir = document.createElement("span");
divNameDir.className = "li_normal";
var id = 'idPick' + i;
divNameDir.setAttribute('id',id);
// alert(divNameDir); // debug.
divNameDir.onmouseover = function ()
{ GetLiveMenus.OnElement(id)}; // highlight li
divNameDir.onmouseout = function ()
{ GetLiveMenus.OutElement(id)};
try{
// alert(node.childNodes[0].nodeName) // debug.
if (node.childNodes[0].nodeName == "#text"){
divNameDir.appendChild(node.childNodes[0]);
node.insertBefore(divNameDir,node.firstChild);
}
}catch(e){
alert('exception in iteration ' + i + ', error: ' + e);
}
} // fin for
} // end constructor
GetLiveMenus.OnElement = function ( menu ) {
var ele = document.getElementById(idl);
ele.className = "li_normal_hover";
}
// style for highlight the element.
..li_normal_hover{
margin: 1px;
padding-bottom: 2px;
padding-top: 1px;
padding-left: 0px;
padding-right: 5px;
background-color: #FCDB9E;
border-collapse: collapse;
border-color: #000;
border-style: dotted;
border-width: 1px;
color: #000;
cursor: pointer;
}
GetLiveMenus.OutElement = function (idl){
var ele = document.getElementById(idl);
ele.className = "li_normal";
}
..li_normal{
margin: 1px;
border-style: hidden;
border-width: 1px;
margin: 1px;
padding-bottom: 2px;
padding-top: 1px;
padding-left: 0px;
padding-right: 5px;
position: relative;
vertical-align: text-top;
}
recursive function
<UL>
<LI class="li_dir">Lo ultimo en Juegos
<UL>
<LI class="li_dir">Clasicos</LI>
<LI class="li_dir">Novedades</LI>
</UL>
</LI>
</UL>
<script type="text/javascript">
var mn = new GetLiveMenus(); // calling the js
</script>
..li_dir
{
vertical-align: middle;
margin: 2px;
border-style: hidden;
list-style-type: none;
list-style-image: url(/images/folder.gif);
list-style-position: outside;
}
i need to set click, mouseover and mouseout over each "LI" element
to do some task like highlight the desire element and send some
parameter with post. i program a js to do this but when assign the
events to each "LI" it always set the last "LI", following the
example if i put the mouse over the first LI (<LI class="li_dir">Lo
ultimo en Juegos ) highlight the last LI (<LI
class="li_dir">Novedades</LI>), could someone give me some hint about
this issue.
snippet of the code
// constructor
function GetLiveMenus(){
this.nodelist = document.getElementsByTagName("LI");
for (var i = 0; i < this.nodelist.length; i++ ){
var node = this.nodelist;
divNameDir = document.createElement("span");
divNameDir.className = "li_normal";
var id = 'idPick' + i;
divNameDir.setAttribute('id',id);
// alert(divNameDir); // debug.
divNameDir.onmouseover = function ()
{ GetLiveMenus.OnElement(id)}; // highlight li
divNameDir.onmouseout = function ()
{ GetLiveMenus.OutElement(id)};
try{
// alert(node.childNodes[0].nodeName) // debug.
if (node.childNodes[0].nodeName == "#text"){
divNameDir.appendChild(node.childNodes[0]);
node.insertBefore(divNameDir,node.firstChild);
}
}catch(e){
alert('exception in iteration ' + i + ', error: ' + e);
}
} // fin for
} // end constructor
GetLiveMenus.OnElement = function ( menu ) {
var ele = document.getElementById(idl);
ele.className = "li_normal_hover";
}
// style for highlight the element.
..li_normal_hover{
margin: 1px;
padding-bottom: 2px;
padding-top: 1px;
padding-left: 0px;
padding-right: 5px;
background-color: #FCDB9E;
border-collapse: collapse;
border-color: #000;
border-style: dotted;
border-width: 1px;
color: #000;
cursor: pointer;
}
GetLiveMenus.OutElement = function (idl){
var ele = document.getElementById(idl);
ele.className = "li_normal";
}
..li_normal{
margin: 1px;
border-style: hidden;
border-width: 1px;
margin: 1px;
padding-bottom: 2px;
padding-top: 1px;
padding-left: 0px;
padding-right: 5px;
position: relative;
vertical-align: text-top;
}