开发者

first-child selector means what? Select the first-child of the element? Or select it if it is the first-child?

Look at this:

var selection= $(开发者_运维百科'table td:first-child');

In practice it selects the first row's <td> elements in the table.

When I saw it for the first time, I took it as: Select all first-child elements within all <td> in the <table> </table>.

But what it does is: Select all <td> within the table if it is the first-child of its parent. Means first <td> between each tags.

So, the question is, does first-child selector works like a flag? Or it works like a kind of method to get the first-child of the element in question in the jQuery wrapper-set?

thanks,


Firstchild will get the TD within the table that are the first child within their parent. If you wanted what you intially though it'd be something like table td > *:first-child. Think of it like the rest of the : filters jQuery provides: hidden, disabled, checked, etc. It applies to the element in the selector it is attached to.


the :first-child selector can match more than one: one for each parent. This is equivalent to :nth-child(1).

source: here.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜