Skip to content

Instantly share code, notes, and snippets.

@intruxxer
Created December 2, 2013 07:19
Show Gist options
  • Save intruxxer/7746186 to your computer and use it in GitHub Desktop.
Save intruxxer/7746186 to your computer and use it in GitHub Desktop.
sethrefs = function () {
if (document.querySelectorAll) {
var datahrefs = document.querySelectorAll('[data-href]'),
dhcount = datahrefs.length;
while (dhcount-- > 0) {
var ele = datahrefs[dhcount],
link = function (event) {
var target = event.target;
if (!event.target.href) window.location.href = this.getAttribute('data-href');
};
if(ele.addEventListener) ele.addEventListener('click', link, false);
else ele.attachEvent('onclick', link);
}
}
};
sethrefs();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment