Reputation: 121
I need simple JS code(pure JS,no frameworks) to rewrite piece of text into linked anchor(hyperlink) when visitor load page.
Or to be more precise, something same like many advertising services using: - put JS on existing page - when JS is fired it connect to my servers, find some data and rewrites certain phrases in page content into hyperlinks
For now I done part of job where fired JS contact my server, finding appropriate phrases which will convert to hyperlinks, but don't have idea how to rewrite phrase on page into hyperlink.
So, if any body have pure JS solution for this please share with me :)
Upvotes: 2
Views: 1123
Reputation: 5356
hrefPath is path which you can find to your server for rewrite
document.getElementById("ID").href=hrefPath;
or
document.getElementsByTagName('a')[0].href=hrefPath;
change index with 0 to your requirdment
Upvotes: 2