[].forEach.call(document.querySelectorAll('td[data-href]'), function(el) { el.addEventListener('click', function (event) { window.document.location = this.getAttribute('data-href'); }); }); $('td[data-href]').on('click', function() { window.document.location = $(this).attr('data-href'); }); /* This method as the advantage that if you add new elements to the document the event listener will still work */ document.addEventListener('click', function(e) { if (e.target.tagName === 'TD' && e.target.hasAttribute('data-href')) { // For historical reason tagName is always uppercase window.document.location = e.target.getAttribute('data-href'); } }); $(document).on('click', 'td[data-href]', function() { window.document.location = $(this).attr('data-href'); });