Reputation: 531
I'm trying to prevent a Jquery onclick function to scroll the page to the top. I found out that preventDefault() would fix this problem but I can't get it to work.
Here's the website with the code: http://www.femartins.com.br/novo/galeria.html
Here's the code that I'm using:
$( document ).ready(function() {
$('.carouselObj').click(function(evt){
var index = $('.carouselObj').index(this);
$('.galcontent').eq(index).siblings('.galcontent').fadeOut(500,function() {
$('.galcontent').eq(index).fadeIn(500);
evt.preventDefault();
});
});
});
Any help is welcome! :)
Upvotes: 0
Views: 62
Reputation: 531
Figure the problem wasn't on click but the way the html was built. I added a div with the same height as the content and the problem was solved!
Thanks
Upvotes: 0
Reputation: 133403
You need to use evt.preventDefault();
in the event handler. Not in the complete callback function of fadeOut
$('.carouselObj').click(function (evt) {
//Use here
evt.preventDefault();
var index = $('.carouselObj').index(this);
$('.galcontent').eq(index).siblings('.galcontent').fadeOut(500, function () {
$('.galcontent').eq(index).fadeIn(500);
});
});
Upvotes: 3