can't get .indexOf to return expected value

can't get .indexOf to return expected value

This question was asked, and I would like to include additional info for the solution.

Original post:

I'm trying to select all elements that has a class that starts with "col-md", but no matter what I do .indexOf("col-md") returns -1.

Html:
  1. <div class="col-md-4">
  2.     Test 1
  3. </div>
  4. <div class="col-md-8">
  5.     Test 2
  6. </div>

jQuery:
  1. if ($col.attr("class").indexOf("col-" + val.toLowerCase()) > -1) {
  2.     console.log($col);                               
  3. }

val is "MD"

Original post ends here

----------------------------------------------------------------------------------


also here is a jsfiddle:


Jim