Reputation: 4211
How can I append #somehash to all links on a page without depending on a JS framework?
Or is it possible to catch when someone clicks on a link and attach #somehash?
Upvotes: 0
Views: 358
Reputation: 30160
As pointed out, you're probably doing this the wrong way, but...
var links = document.getElementsByTagName('a');
for(var i = 0; i < links.length; i++) {
var link = links[i];
if (link.href.indexOf('#') < 0) {
link.href += '#somehash';
}
}
Upvotes: 3
Reputation: 39019
Make the server add hashed?
Otherwise you will need JS. PS, how do you plan to do anything useful with the hashes without JS enabled?
Upvotes: 1