开发者

Select first element of filtered list jQuery

I have a function with a chain of filters in jQuery. I am trying to set the focus() on the first element of my last filtered set of elements.

This gives me my desired result set, so I've gotten that far:

$("div[class='st_d']").filter(function() {
     return !($(this).css('visibility') == 'hidden' || $(this).css('display') == 'none');
  }).find(开发者_运维技巧":input[type=text]");

What I am trying to do is something like this, where on my desired result set, set focus on the first element in that result:

$("div[class='st_d']").filter(function() {
     return !($(this).css('visibility') == 'hidden' || $(this).css('display') == 'none');
  }).find(":input[type=text]:first").focus();

Thanks!


use .eq() to reduce the result set to a single element by its index, eg

$("div[class='st_d']").filter(function() {
     return !($(this).css('visibility') == 'hidden' || $(this).css('display') == 'none');
  }).find(":input[type=text]").eq(0).focus();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜