Posted By


shabith on 04/27/11

Tagged


Statistics


Viewed 663 times
Favorited by 0 user(s)

IE7 Array indexOf() fix


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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

You need to login to post a comment.