views:

42

answers:

1

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!

+1  A: 

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();
Graza
Awesome, thank you!
jaywon