1

Getting elements with a partial attribute match in jQuery is pretty easy. For instance

section[id^="sect_"]

would get all elements with ids bearing the form sect_xxxx. However, I need to to a step further and fetch - this is in a jQuery Mobile application - the section that is currently visible and bears an id with that form. I have tried combining the :visible modifier in various ways but drawn a blank. I'd be grateful to anyone who could suggest the right format.

4

3 回答 3

4

尝试这个

$('section[id^="sect_"]').filter(':visible');

实际上,该filter方法允许您在当前 DOM 选择中设置选择器。请参阅jQuery 过滤器

于 2013-03-15T08:15:09.077 回答
1

尝试这个

检查元素是否可见使用 is()

 $('section[id^="sect_"]').is(':visible'){  //to check if it is visible..
      //your stuff if visible
  }

要获得所有可见的元素,您可以使用..也可以:visible使用过滤器..

$('section[id^="sect_"]:visible')
于 2013-03-15T08:14:28.993 回答
0

Another solution is to see if it's not hidden :

$('section[id^="sect_"]').not(':hidden').hide();

See on this fiddle for example.

于 2013-03-15T08:18:08.383 回答