Reputation: 103
I want to to fadeOut the previous and the next class of a specific one, why my code isnt working? You know the solution?
Note: How to specify that the previous of #homebut is #aboutus, and that the next of#aboutus is #homebut?
Thanks a lot for any help!
This is my html-code:
<body>
<div class="menuEintraege" id="2">
<li class="current"><a href="home.html" id="homebut">home</a></li>
<li><a href="apps.html"id="appsbut">apps</a></li>
<li><a href="hedone.html" id="hedonebut">hedone</a></li>
<li><a href="contact.html" id="contactbut">contact</a></li>
<li><a href="aboutus.html" id="aboutusbut">about us</a></li>
</div>
</body>
and this my javascript till now:
$("a").click(function() {
$(this).prev("li").fadeOut("fast");
$(this).next("li").fadeOut("fast");
}
Upvotes: 0
Views: 130
Reputation: 253328
My first thoughts, would be:
$('li a:first').addClass('active');
$('button').click(function(e) {
e.preventDefault();
var that = this,
$that = $(that),
aEls = $('.menuEintraege a'),
aActive = $('.menuEintraege a.active')
.closest('li')
.index();
if (that.id == 'pre') {
$('.active').removeClass('active');
var pre = aEls.eq(aActive - 1);
var prev = pre.length ? pre : aEls.last();
prev.addClass('active');
}
else if (that.id == 'nxt') {
$('.active').removeClass('active');
var pre = aEls.eq(aActive + 1);
var prev = pre.length ? pre : aEls.first();
prev.addClass('active');
}
});
Upvotes: 1
Reputation: 17000
$("a").click(function() {
$(this).parent().prev("li").fadeOut("fast");
$(this).parent().next("li").fadeOut("fast");
}
Upvotes: 1