I want to add a class to an object when I click on an div with the class "arrow right" or "arrow left". On http://jsfiddle.net/ does it work perfect. But on my Site it doesn't work :(
Can anyone help me?
jQuery:
var currentPage = 0;
var lastPage = ($(".post-preview > div").length)-1;
currentPage = $('.post-preview > div.show').attr('id');
$('.news > .right').stop().click(function() {
if (currentPage == lastPage) {
$('.post-preview > div#' + lastPage).hide();
$('.post-preview > div#' + lastPage).removeClass('show');
$('.post-preview > div#0').fadeIn(300);
$('.post-preview > div#0').addClass('show');
currentPage = 0;
} else {
$('.post-preview > div#'+currentPage).hide();
$('.post-preview > div#'+currentPage).removeClass('show');
currentPage++;
var nextPage = currentPage;
currentPage--;
$('.post-preview > div#'+nextPage).fadeIn(300);
$('.post-preview > div#'+nextPage).addClass('show');
currentPage = nextPage;
}
});
$('.news > .left').stop().click(function() {
if (currentPage == 0) {
$('.post-preview > div#0').hide();
$('.post-preview > div#0').removeClass('show');
$('.post-preview > div#' + lastPage).fadeIn(300);
$('.post-preview > div#' + lastPage).addClass('show');
currentPage = lastPage;
} else {
$('.post-preview > div#'+currentPage).hide();
$('.rpost-preview > div#'+currentPage).removeClass('show');
currentPage--;
var nextPage = currentPage;
currentPage++;
$('.post-preview > div#'+nextPage).fadeIn(300);
$('.post-preview > div#'+nextPage).addClass('show');
currentPage = nextPage;
}
});
CSS for show class:
.news > .post-preview > div.show { display: inline-block !important; }
My HTML Code:
<div class="news">
<div class="arrow left"></div>
<div class="post-preview">
<div id="0" class='show'></div>
<div id="1"></div>
<div id="2"></div>
</div>
<div class="arrow right"></div>
</div>