Reputation: 2377
I always forget how to select an element inside this in jQuery. I tried something like $(this+'a') but unfurtunately that does not work correctly. Here's a share of my code that i'm currently working with:
var currlink = $(this+'a').attr('href');
Good weeekend! :)
Upvotes: 1
Views: 89
Reputation: 7467
You can also use the find() function:
$(this).find('a').prop('href');
For the time being, .prop acts almost similarly to .attr with a few discrepancies, but .attr is deprecated in the lates versions of jQuery
You can also do
$(this).find('[href=http://domain.tld]');
The above will get an element whose href is equal to http://domain.tld
Upvotes: 0
Reputation: 39023
If you want to select an element that is contained in another element in the DOM, do this:
var outer = $(this)
var inner = $('a', outer)
Or, in short:
$('a', this).attr('href')
Upvotes: 0