/ 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/
source: http://www.robsearles.com/2010/03/11/ie-7-indexof-replacement/
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* this will work in all browsers(no jQuery needed) */ if (!Array.indexOf) { Array.prototype.indexOf = function (obj, start) { for (var i = (start || 0); i < this.length; i++) { if (this[i] == obj) { return i; } } return -1; } } //call var i = haystack_array.indexOf("needle") /* or you can use jquery instead */ //call var i = jQuery.inArray("needle", haystack_array)