Posted By

shabith on 04/27/11


Tagged

fix array jquery bug ie7 indexof


Versions (?)

IE7 Array indexOf() fix


 / Published in: JavaScript
 

source: http://stellapower.net/content/javascript-support-and-arrayindexof-ie/ source: http://www.robsearles.com/2010/03/11/ie-7-indexof-replacement/

  1. /* this will work in all browsers(no jQuery needed) */
  2. if (!Array.indexOf) {
  3. Array.prototype.indexOf = function (obj, start) {
  4. for (var i = (start || 0); i < this.length; i++) {
  5. if (this[i] == obj) {
  6. return i;
  7. }
  8. }
  9. return -1;
  10. }
  11. }
  12.  
  13. //call
  14. var i = haystack_array.indexOf("needle")
  15.  
  16.  
  17.  
  18.  
  19. /* or you can use jquery instead */
  20.  
  21. //call
  22. var i = jQuery.inArray("needle", haystack_array)

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: shabith on April 27, 2011

source: http://stellapower.net/content/javascript-support-and-arrayindexof-ie/ source: http://www.robsearles.com/2010/03/11/ie-7-indexof-replacement/

You need to login to post a comment.