0

Instead of writing a temporary boolean, an $.each() on an array of <select> elements, and find if one's prop('selectedIndex') > 0, I'd like to do something like:

$('select[id^="idPrefixForTheArrayOfSelects-"][selectedIndex="0"]').length == 0

but it doesn't work.

Is it possible to select by value, selectedIndex, etc?

  • `selectedIndex` is a property not an attribute on select. What you have is a attribute selector. Read more http://stackoverflow.com/a/5876747/297641 – Selvakumar Arumugam May 24 '13 at 16:26

1 Answers1

5

You can do this -

$('select[id^="idPrefixForTheArrayOfSelects-"]').filter(function(){
 return this.selectedIndex === 0;
}).length == 0
Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111
  • beautiful! used the same thing for my textbox/textarea arrays with `$(this).val()`. ty! –  May 24 '13 at 23:55