开发者

Select first element of filtered list jQuery

开发者 https://www.devze.com 2022-12-27 12:59 出处:网络
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.

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

精彩评论

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