最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - PrototypeJS: Selecting visible elements - Stack Overflow

programmeradmin1浏览0评论

I am trying to formulate a selector to select a set of visible elements. Our application uses the Prototype JavaScript framework, version 1.6.0.3.

The markup I'm working with is as follows:

<ul>
    <li style="display:none;">1 Hidden</li>
    <li style="display:none;">2 Hidden</li>
    <li style="">3 Visible</li>
    <li style="display:none;">4 Hidden</li>
    <li style="display:none;">5 Hidden</li>
    <li style="display:none;">6 Hidden</li>
    <li>7 Visible</li>
    <li style="">8 Visible</li>
</ul>

As you can see, some elements may have a style attribute, but only the hidden ones contain the string "display:none;". I need to select the <li> elements that are visible, where visibility is defined as "does not contain display:none".

What I've tried to far:

var visibleItems = $$('li[style*="display:none"]'); // Yields: [ ]
var visibleItems = $$('li[style*="display"]'); // Yields: [li, li, li, li, li], but isn't specific enough

Ideas? Ideally I'd like this to be as pact as possible, but I'll take what I can get.

Yes, I know that jQuery can do this but I do not want to introduce another framework in to this application since much of it already depends on Prototype.

I am trying to formulate a selector to select a set of visible elements. Our application uses the Prototype JavaScript framework, version 1.6.0.3.

The markup I'm working with is as follows:

<ul>
    <li style="display:none;">1 Hidden</li>
    <li style="display:none;">2 Hidden</li>
    <li style="">3 Visible</li>
    <li style="display:none;">4 Hidden</li>
    <li style="display:none;">5 Hidden</li>
    <li style="display:none;">6 Hidden</li>
    <li>7 Visible</li>
    <li style="">8 Visible</li>
</ul>

As you can see, some elements may have a style attribute, but only the hidden ones contain the string "display:none;". I need to select the <li> elements that are visible, where visibility is defined as "does not contain display:none".

What I've tried to far:

var visibleItems = $$('li[style*="display:none"]'); // Yields: [ ]
var visibleItems = $$('li[style*="display"]'); // Yields: [li, li, li, li, li], but isn't specific enough

Ideas? Ideally I'd like this to be as pact as possible, but I'll take what I can get.

Yes, I know that jQuery can do this but I do not want to introduce another framework in to this application since much of it already depends on Prototype.

Share Improve this question edited Dec 27, 2011 at 17:20 Rob W 349k87 gold badges807 silver badges682 bronze badges asked Apr 28, 2009 at 4:45 Zack The HumanZack The Human 8,4918 gold badges42 silver badges61 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

You can filter the items using the findAll function:

var notVisible = $$('li').findAll(function(el) { return !el.visible(); });
发布评论

评论列表(0)

  1. 暂无评论