As the title says, i try to add a jquery hover effect to different a-tags within a for loop. The hover-effects are added but the hide-show-functionality inside seems to be wrong. i always get the selector for the last li-element.
Any help would be great.
here's the code:
html:
<a id="o1" href="#">Show Text 1</a>
<a id="o2" href="#">Show Text 2</a>
<a id="o3" href="#">Show Text 3</a>
<a id="o4" href="#">Show Text 4</a>
<a id="o5" href="#">Show Text 5</a>
<ul class="subTxt">
<li id="u1">Text 1</li>
<li id="u2">Text 2</li>
<li id="u3">Text 3</li>
<li id="u4">Text 4</li>
<li id="u5">Text 5</li>
</ul>
javascript:
/* Hide li's */
$("ul.subTxt").find("li").each(
function() {
$(this).hide();
});
/* Add Hover-Events */
for (var a = 1; a < 6; a++) {
var k = '#o' + a;
var e = '#u' + a;
$(k).hover(
function() {
$(e).show();
$(this).append('<div id="hk" style="position: relative;float: right;">' + k + ' ' + e + '</div>');
}, function() {
$(e).hide();
$(this).find('#hk').remove();
});
}