' + val.product + ''; I have creat" /> ' + val.product + ''; I have creat" /> ' + val.product + ''; I have creat"/>

creating a link to a div

39 Views Asked by At

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

1

There are 1 best solutions below

0
AndrewL64 On

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.