Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

page jump from div to an anchor

I was trying to make a div jump from <a href="#FAQ">FAQ</a> to a div id and could success easily, but since I have a fixed link to jump to, I can't seem to find a way how to do that.

Meaning, I want a div or a href link to jump to a url in the same page say <a href="http://www.mydomain.ask.html">Ask</a>

I know for sure that jumping from an anchor such as <a href="#jump">jump</a> to a div such as <div id="jump">jump to point</div> works fine. However, how about the opposite way? does it work? I mean jumping from div id to an anchor works?

like image 354
Digital site Avatar asked Jul 23 '13 14:07

Digital site


People also ask

How do I jump to an anchor on another page?

In the URL field, enter the # hashtag symbol, followed by the name of the anchor. If you want to link to an anchor on an external page, you can enter the full URL, then the # hashtag symbol, followed by the name of the anchor.

How do I link an anchor tag to a div?

You can now link to this section (div) using the anchor tag. To do that, just use the id of the section with a # as the prefix for the href value.

How do you jump to a specific section in HTML?

Method 1: Using HTML: One can use the anchor tag to redirect to a particular section on the same page. You need to add ” id attribute” to the section you want to show and use the same id in href attribute with “#” in the anchor tag.


1 Answers

As long as your anchor has an ID you can link to a location in your view by clicking the div you will just need some javascript.

Setting the window.location.hash value will put the focus of the view on the selected ID.

Sample

<a href="#test1" id="back">Test</a>

<div id="test1" onclick="window.location.hash='back'; ">

JSFiddle Example

like image 67
Malkus Avatar answered Oct 07 '22 23:10

Malkus