If you don't want to iterate over all your anchor elements, you can simply use event delegation, for example:
document.onclick = function (e) {
e = e || window.event;
var element = e.target || e.srcElement;
if (element.tagName == 'A') {
someFunction(element.href);
return false; // prevent default action and stop event propagation
}
};
Check the above example here.
Using jQuery:
$(function() {
$("a").click(function() {
return someMethodName($(this).attr('href'));
});
});
function someMethodName(href)
{
console.log(href);
return false;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With