Reputation: 6980
I have a situation where I need to use $(this) in the options for the position function. I have two dropdowns where each needs to be centered below their corresponding button. I do no want to add extra ID's or anything to the DOM as this code will be used multiple times in one page. Here's a fiddle.
$(".dropDown .dialogueBox").position({
my: "center top",
at: "center bottom",
of: $(this).parent().children(".drop-button"),
collision: "none"
});
Upvotes: 0
Views: 27
Reputation: 56467
Loop through each element and then you will have access to $(this)
:
$(".dropDown .dialogueBox").each(function() {
var that = $(this);
that.position({
my: "center top",
at: "center bottom",
of: that.parent().children(".drop-button"),
collision: "none"
});
});
Read more about .each
here:
Upvotes: 1