【问题标题】:How to include current element within result of Element.select?如何在 Element.select 的结果中包含当前元素?
【发布时间】:2015-04-25 11:34:57
【问题描述】:

是否可以将当前元素作为条目添加到Element.select 的结果中?

背景:我想为一个元素和它的一些子元素应用一个特定的类名。所以像 myElem.select('this, .childElements').invoke('addClassName', 'alice') 这样的东西会很酷 - 但是,当然,this 在这里不是有效的关键字。

Prototype.js Docs for Element.select

【问题讨论】:

    标签: javascript css-selectors prototypejs


    【解决方案1】:

    不幸的是,该行为不是select() 方法的目标。但是,您可以通过转到 myElem 父元素来获得所需的结果。

    myElem.up().select('.childElements, .parentElement').invoke('addClassName','alice')
    

    【讨论】:

      猜你喜欢
      • 2010-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-17
      • 2019-03-06
      • 2016-10-21
      • 1970-01-01
      • 2018-05-17
      相关资源
      最近更新 更多