In an html file I have a header tag in which there is a menu where in the a tags through the href I link to the id of the div that I want and another main tag where I create several divs and it works perfectly when in the href attribute of the tag I call to the id of the desired div; My problem is when I'm in another html file I have no idea how to link to the div of the first page.html in the href of the a tag of the menu that this page shows.
I have tried <a href="index.html/#et-ia">ingeniero / arquitecto</a></li>
but when I try to run it in the browser it tells me that the file cannot be accessed, in the same way I tried putting
<a href="/HTML/index.html/#et-ia">
y <a href="../HTML/index.html/#et-ia">
(at the beginning I put 2 points because to link an image I could only access the file by putting that at the beginning of the path ), maybe they have some option to solve this problem
Look in the href attribute I left out the "/" before the "#" and it already directed me to the div that is in the other html file.
<a href="../HTML/index.html#et-ia">
I hope that this can also help other people who may have the same concern that I had at the beginning and thanks for the contribution of other users.
With plain HTML, you always point to anchors ( tags
<a>
), whose function is to offer a link to allow navigation between HTML documents. They should not always have a hyperlink to another resource.The key is to remember that HTML is a document created following a standard. The tags that we create in the DOM give it semantic meaning or provide tools to paint the document in some way, but it is a document.
Example case: any page like... https://code.visualstudio.com/docs/python/environments
This page has multiple sections (as a document, semantically, not in the DOM). Subtitles, we would say.
This section that I randomly picked has a
#
next to the title and if you hover...you will see a link to that anchor (
https://code.visualstudio.com/docs/python/environments#_manually-specify-an-interpreter
)When reviewing that document, it is seen that that anchor is defined like this:
Thus, if you share that link, the browser anchors on that anchor and paints the page focused on that part of the content.
Summary, it does not point to a div but to anchors. This has been around for a while already in HTML. To do what you're looking for, by targeting a div, you may need to send parameters in the URL and have JS code interpret the URL parameters, look for the div with that id, and scroll the page.
Something like you send it
http://URL?pageFocus=blablatab
and your JS code validates onLoad , use the parameters the page was loaded with and do something like