11

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;
    }
davidkonrad
  • 83,997
  • 17
  • 205
  • 265
user1107009
  • 111
  • 1
  • 1
  • 5

5 Answers5

23

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.

Erick Ashri
  • 341
  • 2
  • 6
11

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).

Community
  • 1
  • 1
ansorensen
  • 1,276
  • 1
  • 14
  • 29
  • 2
    display: none did the trick. I was hiding the checkboxes at -999px, -999px with a label on the screen. When I clicked on one, unlike radio buttons, the screen tried to scroll to display the checkbox that was selected. I originally avoided display: none because that used to disable the checkbox. This is no longer the case and may have been an IE6 thing. If display: none interferes with the page's operation, you might try position: relative; left: -999px so that it does not scroll vertically in its attempts to display it. – Mike Oct 28 '14 at 07:33
  • 1
    I'm having this issue on an extension. It's not the checkbox that's hidden for me though. The checkbox triggers a click that enables or disables a textbox. When the textbox enables or disables, Firefox jumps to the top of the page. I have no idea why or how this is happening and I've tried a dozen workarounds. – ElJeffe Mar 21 '17 at 13:33
4

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.

2

If the checkbox has been positioned absolute to hide it and the interaction occurs on the label (which is commonplace when styling checkboxes beyond the default UI), the page will scroll to wherever the checkbox input is positioned despite the click event occurring on the label. so if you've added top:-9999px; for example, the page will jump right up to where it's now positioned. What you want instead, is to remove it from the rendered layout without moving it away from the label. to do this, add a container div to the label and input, and add position:relative; to it. Then add the following code to the input itself:

position:absolute;
top:0; left:0;
visibility: hidden;
opacity: 0;
ToddPadwick
  • 430
  • 1
  • 6
  • 13
0

If your check box has position: absolute, in most cases just wrapping it (input and label elements) with a div should be enough.

charles okojie
  • 708
  • 2
  • 10
  • 23