tags:

views:

64

answers:

3

Hi,

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.

+2  A: 

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">
Oded
Why the downvote?
Oded
For suggesting deprecated HTML.
RoToRa
@RoToRa - can you please point me to the source that shows this is deprecated?
Oded
@Oded: The attribute isn't even in the [HTML5 spec for <a>](http://www.whatwg.org/specs/web-apps/current-work/multipage/text-level-semantics.html#the-a-element)
Andy E
http://www.w3.org/TR/xhtml1#h-4.10. 'name' is formally deprecated and 'id' is to be used instead.
Marc B
@Andy E - fair enough.
Oded
What they said ;-)
RoToRa
@RoToRa - answer updated.
Oded
You can just put the `id` on the `div`. There is no real point in having a "orphaned" link.
RoToRa
The id doesn't have to be on an `<a>` element in HTML 4, although I can see how the spec is a little unclear on that.
David Dorward
@David Dorwards - thanks for the correction. @RoToRa - I see what you mean now. Answer updates (for the last time?)
Oded
+5  A: 

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> 
Andy E
Can you please point me to the source that shows `name` is deprecated?
Oded
@Oded: [here](http://www.w3.org/TR/xhtml1/#h-4.10) in XHTML 1.0, and [the <a> element](http://dev.w3.org/html5/spec/Overview.html#the-a-element) in HTML 5 doesn't define the attribute.
Andy E
yes thats what I have and it still just goes to the home div instead!
C.
+1  A: 

Don't use an anchor. That is outdated. Just give the DIV the id product:

<div id="product">...</div>
RoToRa