0

is it possible to create a link to a div? this is my line of code:

     output +='<h2><a href=\"link-to-a-website" >' + val.product + '</h2>';

I have created a rich internet application and I need this to link to a div within my website

AndrewL64
  • 15,794
  • 8
  • 47
  • 79
lauren
  • 35
  • 5
  • You can link using an ID. Given `
    ...`, link using `foo` Duplicate of http://stackoverflow.com/questions/484719/html-anchors-with-name-or-id?
    – qux Apr 19 '16 at 22:21

1 Answers1

0

Yes it is possible but you need to use ID instead of CLASS.

Example:

<h2><a href="#targetDiv" >' + val.product + '</a></h2>

<div id="topDiv">
</div>
<div id="targetDiv">
</div>

jsFiddle: https://jsfiddle.net/AndrewL32/45o6u4Le/2/


The target div could be on a different page/site too but you will have to specify the path correctly.

AndrewL64
  • 15,794
  • 8
  • 47
  • 79