开发者

jQuery: Multiple selectors including this

开发者 https://www.devze.com 2023-01-25 06:33 出处:网络
i want to sel开发者_运维百科ect ´this´ and something else. for example: $(this + \', \' + this + \' > div\')

i want to sel开发者_运维百科ect ´this´ and something else. for example:

$(this + ', ' + this + ' > div')

how can i make this work? Is this possible in a single selector?


You can use .andSelf() to hop back in the chain and include the element before as well, like this:

$(this).children("div").andSelf()

So we go from this to it's children, then .andSelf() adds to that collection what was in the chain before, which was this.


You can add a result to another:

$(this).add('div', this)
0

精彩评论

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