I'm having a set of tables that hide and show content when clicked on their th. Also I'm using scrollTop to reach to the top of each clicked table to better show its content. No problem so far... By default, I want the first table to show its content but I want to prevent the scrollTop in this case when the page loads. How can I do it?
$(document).ready(function() {
$('table tr').nextAll().hide();
var $button = $('table th').css('cursor', 'pointer');
$button.click( function() {
$(this).parent().nextUntil('table th').toggle();
$('html, body').animate({
scrollTop: $(this).offset().top
}, 500);
});
$('table th:eq(0)').trigger('click', animate(false));
});
There must be some piece of code on .trigger() that helps me prevent this first scroll? Thanks for your help!
EDIT: Well, not the most elegant of solutions but splitting the events and having the trigger() placed before the animations seemed to work:
$(document).ready(function() {
$('table tr').nextAll().hide();
var $button = $('table th').css('cursor', 'pointer');
$button.click( function() {
$(this).parent().nextUntil('table th').toggle();
});
$('table th:eq(0)').trigger('click');
$button.click( function() {
$('html, body').animate({
scrollTop: $(this).offset().top
}, 500);
});
});