Search code examples
javascriptcss-selectorsprototypejs

How to include current element within result of Element.select?


Is it possible to add the current element as an entry to the result of Element.select?

Background: I want to apply a specific class name to an element and some of its children. So something like myElem.select('this, .childElements').invoke('addClassName', 'alice') would be cool - but, of course, this isn't a valid keyword here.

Prototype.js Docs for Element.select


Solution

  • Unfortunately that behavior is not the target of the select() method. However you can get the results you are looking for by going up to myElem parent element.

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