Reputation: 4908
I've got the following selector:
$(this).children('li').children('a')
It seems a bit clunky, can it be shortened?
Upvotes: 1
Views: 102
Reputation: 4399
The shortest one, in my opinion is $(">li>a",this)
.
If you are sure there is no other li
's in A innerHTML, maybe you can short to $("li>a",this)
.
Upvotes: 0
Reputation: 8101
It can be shortened very little, so it looks like this:
$('li', this).children('a')
Upvotes: 1
Reputation: 165971
You could use find
, but I don't think it's much shorter really:
$(this).find("> li > a");
Note the use of the >
child selector, so it only finds li
elements that are direct children of this
(as the children
method in your original code would).
Upvotes: 2