开发者

Help me understand this one line of jQuery

开发者 https://www.devze.com 2023-01-15 10:22 出处:网络
var div = $(this), ul = $(\"ul\", div)开发者_如何学Python, li = $(\"li\", ul); Please explain, what does this code do?
var div = $(this), ul = $("ul", div)开发者_如何学Python, li = $("li", ul);

Please explain, what does this code do?

By steps.

Thanks.


It ends up with these equivalents:

var div = $(this);
var ul = $(this).find("ul");
var li = $(this).find("ul").find("li");

So it's getting the current <div>, any <ul> elements inside it, and any <li> elements inside those, and placing each collection in its own variable.

When you do $(selector, content) you're actually doing $(context).find(selector) under the covers, so the code in your question is just chaining one call to the next, effectively doing a .find() inside each time.

0

精彩评论

暂无评论...
验证码 换一张
取 消