Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Flipswitch standalone widget scrolls to the top of the page when knob is clicked  #8148

@omarshammas

Description

@omarshammas

Within the flipswitch widget, when the knob is clicked I'm taken to the top of the html page.

Steps to reproduce:

  • download a custom build of jquery mobile where only the flipswitch widget and its dependencies are selected.
  • create a basic html page and paste this in the body of the html
  <div style='height: 1000px;'></div>
  <input type='checkbox' id='jqm-test'/>
  <script>
    $('#jqm-test').flipswitch(); //.parent('.ui-flipswitch').on('click', 'a', function(e) { e.preventDefault(); });
  </script>
  • make sure you scroll down so the window is not at the top of the page already
  • click the knob
  • you will be taken to the top of the page

It appears the knob is actually a hyperlink element with an attribute href='#'. The click event is never caught in the standalone version hence the user is taken to the top of the page.

<div class="ui-flipswitch ui-shadow-inset ui-bar-inherit ui-corner-all ui-flipswitch-active">
  <a href="#" class="ui-flipswitch-on ui-btn ui-shadow ui-btn-inherit">On</a>
  <span class="ui-flipswitch-off">Off</span>
  <input type="checkbox" id="jqm-test" class="ui-flipswitch-input" tabindex="-1">
</div>

In the meantime I've added an event listener that prevents the default behavior.

$('#jqm-test').flipswitch().parent('.ui-flipswitch').on('click', 'a', function(e) { e.preventDefault(); });

Thanks!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions