Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page jumps to the top when checkbox is clicked

I'm calling handleNotableTypeSelect method on the click of the check box, everything is working fine but the page jumps to the top.

this.$hideInactiveCheckbox.click(
    this.handleNotableTypeSelect.createDelegate(this));
    handleNotableTypeSelect: function(e) {
        //e.preventDefault();
        if (this.$hideInactiveCheckbox.attr('checked')) {
            this.isActive = "^active$";     
            this.$connTable.fnFilter(this.isActive, 1,true);     
        }
        else {
            this.$connTable.fnFilter('', 1);
        } 
        //return false;
    }
like image 266
user1107009 Avatar asked Dec 20 '11 02:12

user1107009


3 Answers

My case was that the checkbox was hidden (due to CSS design). the original input checkbox had position set to 'absolute' so when the user clicked the checkbox the page "jumped" to the real checkbox position.

EDIT:

In some cases there are styled "fake" checkboxes. the real checkbox element is hidden in some bad practice way. My case was that the real checkbox element had absolute positioning and hidden and that cause the page jump to top of the window.

Possible solution:

Check if the checkbox element has the following CSS rule position: absolute;
if yes, removing this rule can fix this issue.

like image 133
Erick Ashri Avatar answered Oct 31 '22 11:10

Erick Ashri


This may related to the following issue:

input checkbox in div jumps to top of page on firefox

I've actually been seeing errors about this in all kinds of frameworks, and for the most part, people post framework specific answers. If you're hiding the check box, try using display: none on it, it seemed to work for the post above. I'm still trying to hunt down a fix (since I'm not hiding my checkboxes, I'm trying figure out why checkboxes in a modal cause the screen to jump to the top of the modal on click).

like image 23
ansorensen Avatar answered Oct 31 '22 09:10

ansorensen


Several frameworks and css tricks hide the checkbox using position: absolute. That is correct because we need to hide the checkbox only from screen, while Screen Readers must have access to it in order to announce it correctly. But display:none hides it from them too and users with accessibility issues can't click it. The most suitable solution is to add position:relative to checkbox container and adjust checkbox position using top: if needed.

like image 29
Alexander Stavrou Avatar answered Oct 31 '22 10:10

Alexander Stavrou