I am facing an issue with my ul blocks and buttons that toggle their content. When I click the button to show the content, everything works fine. However, when I scroll down and click the button again to hide the content, the browser screen jumps to the bottom instead of staying at the top of the closed block.
$('.ul' + l).append('<button type="button" onclick="$(this).myFunc()">Button</button>');
$.fn.myFunc = function () {
var ul = $(this).parent().attr('class');
$('.' + ul + ' li:gt(5)').fadeToggle("fast");
};
I have tried using $(window).focus
and adding
fadeToggle("fast").preventDefault()
, but nothing seems to solve the issue. Any suggestions?