检查元素数组中的元素是否具有焦点

时间:2013-10-10 13:04:04

标签: jquery focus

我正在尝试查找未知数量元素中的任何元素是否具有焦点

if($('#wrapper ul li a:focus')) # there are multiple a tags that are dynamically generated

任何人都知道它是如何完成的?

1 个答案:

答案 0 :(得分:3)

$('#wrapper ul li a:focus').length // get the number of items that has focus

$('#wrapper ul li a:focus').eq(0) //get's the first matched element

所以如果你需要检查一组元素中的任何元素是否有焦点

if($('#wrapper ul li a:focus').length){
// do something
}
相关问题