I was looking at some code from a tutorial for creating a carousel menu and noticed parent child selectors without the parent. Never seen this before, and confused to what it is
There is a parent(or in this case a scope
), notice the this
keyword inside the selector, that's relative to the element the plugin is being applied to.
jQuery's selectors allow you to set a scope, and it can be any jQuery element object.
Consider
$(".somediv").myplugin();
And inside the plugin
$("> div", this)
is actually translated to
$("> div", $(".somediv"))
Have a look at one of my questions, the answer explains quite a bit about jQuery's selectors. What is the fastest method for selecting descendant elements in jQuery?