Add missing support for array.indexOf()

if (typeof(Array.prototype.indexOf) != "function") {
  Array.prototype.indexOf = function(o) {
    for (var i = 0; i < this.length; i++) {
      if (this[i] === o) return i;
    }
    return -1;
  }
}

Using array.indexOf() to test for a class name

function hasClass(el, c) {
    return el.className && el.className.split(" ").indexOf(c) > -1;
}

Advertisements

About austinfrance

Technical Developer @ RedSky IT / Explorer Software
This entry was posted in JavaScript. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s