Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go to div of another page in HTML

Tags:

html

I would like to go to the DIV of a particular page from a different page. Is that possible?

I tried <a href="file.html#product">Hello</a>

but it just goes to file.html#home

thanks

C.

I have in my file.html but it keeps getting redirected to file.html#home instead.

like image 223
C.. Avatar asked Jul 22 '10 13:07

C..


People also ask

How do I link a div to another page in HTML?

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 to another section of a page?

Tip: You can even jump to a section of another web page by specifying the URL of that page along with the anchor (i.e. #elementId ) in the href attribute, for example, <a href="mypage. html#topicA">Go to TopicA</a> .


2 Answers

file.html will need an element with an id="product" attribute. name is deprecated for <a> tags and shouldn't be used.

<div id="product"></div> 
like image 112
Andy E Avatar answered Sep 21 '22 04:09

Andy E


With HTML 5, you need to simply add an id attribute to your <div> with a value of product. This needs to be a unique id attribute within the page (for all elements):

<div id="product">

See the working draft.

In HTML 4.01 you need to use an anchor tag with a name just above your target div, or any other element with an id attribute in the other page:

<a name="product"></a>
<div>...

See the HTML 4.01 spec.

Note: The name attribute has been deprecated in the XHTML 1.0 spec.

So, this would be a better option, as it would work for HTML 4.01, XHTML 1.0 and HTML 5:

<div id="product">
like image 45
Oded Avatar answered Sep 21 '22 04:09

Oded