I have a simple link which reloads the current page. This is shown below:
echo '<a href="#" id ="mybutton"></a>';
When I click on the link it takes me to the top of the page.
How can I modify it to take me back where the link is located please?
I would also like to give it an offset so the location would not be all the way at the top but there would be a little bit of padding
Try giving the
<a>tag anamefield? Then modify thehrefto direct back to it – i.e.:<a name="thisPosition" href="#thisPosition" id="mybutton">...</a>;EDIT: To reflect the comments, here is an addendum – the ‘name’ field is not strictly required, most (if not all) browsers nowadays can simply identify an ‘id’ attribute, so the href could be modified thusly:
href="#mybutton", forgoing the ‘name’ attribute.