Geetanjali Geetanjali - 5 months ago 28
HTML Question

Link a div to a particular section on a different page in HTML

hey I have a new dilemma.....

I have 3 div like 3 boxes and in each div there is an image and some text written and i want that when i click anywhere in any if the box then it will go to the other page e.g. if i am on home page then on clicking on box then it will go to service.html page in the website.

I have done this by

<div onClick="document.location='service.html';">

and its working.but i want that when user click on first div then it go to service .html and in that particular section and on second box it will go to another section on service.html and so on.......

To be more clear, I want to link a div to a particular section to the particular page..

How can I do this??

Answer Source

You'll have to add an ID to the elements on the service.html page you want to link to, and then include them in your links:

<div onClick="window.location.href='service.html#section-1';">Go to Section 1</div>
<div onClick="window.location.href='service.html#section-2';">Go to Section 2</div>

P.S. Any reason you're using Javascript instead of regular anchor tags?