This works but of course is a bit redundant. Items can also be dynamically added so I need to have it always increment by one. What is a better way to write this into one function?
Update: Just added the markup. Bascially when a user hovers any of the list item a classname should be attached to the banner div. e.g., banner_0, banner_1, etc.
<ul id="list">
<li><a href="#" data="">item1</a></li>
<li><a href="#" data="">item2</a></li>
<li><a href="#" data="">item3</a></li>
<li><a href="#" data="">item4</a></li>
<li><a href="#" data="">item5</a></li>
<li><a href="#" data="">item6</a></li>
<li><a href="#" data="">item7</a></li>
</ul>
<div id="banner" class=""></div>
$('#list a').eq(0).hover(
function() {
$('#banner').addClass('banner_0');
},
function() {
$('#banner').removeClass();
}
);
$('#list a').eq(1).hover(
function() {
$('#banner').addClass('banner_1');
},
function() {
$('#banner').removeClass();
}
);
$('#list a').eq(2).hover(
function() {
$('#banner').addClass('banner_2');
},
function() {
$('#banner').removeClass();
}
);
$('#list a').eq(3).hover(
function() {
$('#banner').addClass('banner_3');
},
function() {
$('#banner').removeClass();
}
);
Try using
.indexlike below,