Search code examples
prototypejs

get all selector with similar class with prototype.js


There is some drop down in my html. I can select all the Drop Down ,if they have certain class by following code.

  var select = dd.down('select');    
  select.hasClassName('test');

But there are some drop down is also with class like 'test-1','test-2' etc.

How can I select those element?


Solution

  • The Prototype 'find by selector' method works like this:

    $$('any css selector here');
    

    This returns an array of extended elements that match your CSS selector. Notably, the selector can be any valid CSS3, so you can use partial matches to find what you're looking for. If you want only the select elements that have test in their classname, you would do this:

    $$('select[class*="test"')
    

    There are many other logical operators you can use in your CSS selectors, there's a great article here that explains them: http://www.456bereastreet.com/archive/200601/css_3_selectors_explained/