<a id="link" href="http://www.google.co.uk">link</a>
<a id="link" href="http://stackoverflow.com">link</a>
the javascript only replaces the first href but i want it to apply to any and all <a> with the id="link" OR do you have a jQuery alternative?
<script>
var link = document.getElementById('link');
var src = link.getAttribute('href');
var paramurl = encodeURIComponent(src);
link.setAttribute("href", "http://mysite.com/?url=" + paramurl);
</script>
Use a class-name instead of an
id:With the JavaScript:
JS Fiddle demo.