How can I get url of clicked anchor text everywhere on the page. I tried this but it only works for "cls" class but not for any anchor.
$('.cls').click(function() {
//here I need to get href url
});
For any anchor in your page you can simply do
$('a').click(function () {
alert($(this).attr('href'));
});
This will give you url of clicked anchor text everywhere on the page.
For more details checkout:-
Try to use .attr('attributeName') to retrieve the clicked element's attribute,
$('.cls').click(function(e) {
e.preventDefault();
console.log($(this).attr('href'));
});
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