jQuery Mobile and hashes

Hi all,

I’m using jQuery Mobile and have run into some issues with hashes in URLs. I have a form which posts to the same page. When the form has been submitted, the page should load and then jump to a div with a specific ID - in the below example, either #one or #two. However, this doesn’t work with JQM. I added data-ajax=“false” to the form, the select menu and the individual options but the pages still load as normal.

Anyone know how to overcome this problem? If you have a solution please share it.

Thank you in advance.

<form class="myform" name="myform" method="POST">
<select>
<option value="/mysite/comment#one">one</option>
<option value="/mysite/comment#two">two</option>
</select>
<input type="submit" value="go">
</form>

Hi all,

the below code could work but it doesn’t. Anyone know why?


$(document).ready(function () {
var h = window.location.hash.substr(1);
h.scrollIntoView();
});  

Thanks!

Hi RedBishop,

Because the Element.scrollIntoView() method scrolls an element into view.
h is not an element n your example, rather a string containing the fragment identifier minus the hash.

Maybe you need to do:

var id = window.location.hash.substr(1),
    el = document.getElementById(id);
el.scrollIntoView(true);

Or something similar.

Thanks for your help Pullo,

I will try that.