[].forEach.call(document.querySelectorAll('a[id]'), function(a,i){ a.onclick = function(event){ event.preventDefault(); window.open(this.dataset.href); location.href = this.href; } });