Getting the index of an element with a given class

Getting the index of an element with a given class

Hello folks,

I have a bunch of elements with multiple classes like this:

  1. <div class="foo bar">
  2. <div class="foo bar snafu">
  3. <div class="foo bar">

I can get all these elements in an array like this:

  1. $ (".foo,.bar")

My question is - is there an elegant way of getting the index (in this array) of the element that has the "snafu" class? Or should I just iterate through the array until I find the wanted element and then remember its index?