Reputation: 59395
I have the selection below, is there any way to make this selection work with $(this)?
(select the second div child of .container)
$(".container div:eq(2)").width();
Upvotes: 0
Views: 190
Reputation: 11
What's wrong with:
$(this).find("div:eq(2)").width()
or:
$("div:eq(2)", this).width()
?
BTW that returns the width of the third div descendant from this
(which unlike div:nth-child(2) may or may not have two siblings before it, :eq() refers to the position in the matching pseudo-array, not in the DOM)
Upvotes: 0
Reputation: 187060
Try
$(".container").each(function(){
$(this).find("div:eq(2)"); // if its not a direct child
});
Upvotes: 1
Reputation: 2928
What you have there already is fine. Why do you want to use $(this)
? You would use $(this)
as an example, in a function:
$(".container div:eq(2)").click(function() {
if( $(this).width > 100 ) {
...
}
});
Upvotes: 0