Reputation: 17018
I am working with a JavaScript framework that performs a callback when a link is clicked. The method includes the full path of the URL that was selected.
Given the URL, is there a JavaScript (or jQuery) selector to target the HTML anchor tag that was clicked?
Upvotes: 2
Views: 399
Reputation: 6321
This one should print, specific clicked tag...
$('a').on('click', function(){
var attr = $(this).attr('href');
console.log(attr);
})
Upvotes: 0
Reputation: 5890
Using jQuery you can use the attribute selector, which goes like [attribute='attribute value']
$('a').click(function () {
var $this = $(this);
var href = $this.attr('href');
var selector = "a[href='" + href + "']";
console.log(this, $(selector));
});
Upvotes: 1