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 the开发者_StackOverflow中文版n 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??
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?
hey i have get ma answer......
<div onClick="document.location='service.html#section1_ID';">
<div onClick="document.location='service.html#section2_ID';">
<div onClick="document.location='service.html#section3_ID';">
and on that section I have used that particular
<div id="section1_ID">bla bla bla</div>
and so on.............
Look on below.
// jQuery method
$('.location').bind("click", function() {
window.location = $(this).data('location');
});
<div class="collection-item location"
data-location="service.html#section1_ID" >
Lorem ipsum, blah
</div>
精彩评论