开发者

selecting using nth child selector jquery

开发者 https://www.devze.com 2023-02-06 09:00 出处:网络
I want to make a selection in jquery using nth child selector I have the index n开发者_如何学Cumber as a variable suggestions;

I want to make a selection in jquery using nth child selector I have the index n开发者_如何学Cumber as a variable suggestions; but $('.search_filter:nth-child('+suggestions+')').focus(); does not focus the 2 element if suggestions=1 so please tell me what I am doing wrong here.


The nth-child-selector(docs) uses a 1 based index to get the sibling at the given index. So if you want the second sibling, you'd use 2.

If they are not all siblings, or you just want a 0 based index, use the eq-selector(docs) instead..


My understanding of the nth-child selector is that, when it's used with a class, it only applies to an element if it is the nth element and has the class. Without seeing any of your code, my guess is you're actually trying to target the nth occurrence of an element with the class "search_filter."

0

精彩评论

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