IE 7 indexOf() Replacement

Posted: March 11th, 2010 | Author: Rob Searles | Filed under: JavaScript | Tags: | Comments

Everyday I hate IE a little bit more, and by the same token, everyday I love jQuery that little bit more.

The reason for my hate/love feelings today was due to a bug caused by IE 7 not supporting the indexOf() method. I have no idea why IE doesn’t support this method, but it is annoying never-the-less. However, there is an easy fix if you are using jQuery – the inArray() function.

The inArray() function is pretty simple to use.

Instead of having:

haystack_array.indexOf("needle")

You should use:

jQuery.inArray("needle", haystack_array)

For those of you crazy nutters that aren’t using jQuery, there is a good post on this blog that will help you out.

If you liked this post, please share it:
  • Digg
  • Reddit
  • Sphinn
  • Facebook
  • del.icio.us
  • YahooMyWeb
  • Furl
  • Mixx
  • Google
  • Fark
  • Live
  • MisterWong
  • StumbleUpon
  • Technorati
  • TwitThis
  • BlogMemes
  • Blogsvine
  • Ma.gnolia
  • Pownce
  • Spurl

Related Posts


blog comments powered by Disqus