I am trying to access a div in another page using an anchor tag and url in Django.
Here is a html,
<a href="{% url 'anotherpage#show' %}>click here </a>
In another page,
<div id="show">link to this div </div>
How would I access the show
div with an url?
By prepending your href with # , you can target an HTML element with a specific id attribute. For example, <a href="#footer"> will navigate to the <div id="footer"> within the same HTML document. This type of href is often used to navigate back to the top of the page.
For example, we can use the name parameter to link to our home page from any other page by adding the following link in a template: <a href="{% url 'index' %}">Home</a>.
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. So, when you click on the Go link, you will scroll to the news section of the 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. In the Button text field, enter the text that will appear on the button.
You need to link to the page first. then link to the Anchor
## assume this will take you to the main page.
<a href="{% url 'anotherpage' %}>Page URL</a>
Then all you have to do is to add the required anchor after the url tag.
<a href="{% url 'anotherpage' %}#show">Page URL to show directly. </a>
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With