I want to use jQuery to go to an anchor with the use of a textbox, for example, I want to use this form:
<form id="gotoanchorform">
<input id="gotoanchorinput" type="text" />
<input type="submit" value="Go to anchor" />
</form>
In this form I would type the name of the anchor and when I click the "Go to anchor" button or press the enter key I want the page to scroll down to that anchor:
<a name="targetAnchor" id="targetAnchor">Target</a>
How would get this to work with jQuery?
HTML part:
NB: data-x attribute is valid HTML.
JS part:
try something like this:
so if you would type "foo" and click submit, the page would scroll to an which name attribute contains "foo"
Simply do:
This piece of code make your page scroll to the anchor written in
#gotoanchorinput
.