Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

link a div in another page in url with an anchor tag Django

Tags:

url

anchor

django

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?

like image 325
user2307087 Avatar asked Jul 27 '15 01:07

user2307087


People also ask

How do I link to a div on a page?

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.

How do I link one page to another in Django?

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>.

How to use div in anchor tag?

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.

How to link to anchor on another page HTML?

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.


1 Answers

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.

like image 190
Othman Avatar answered Nov 15 '22 05:11

Othman