Reputation: 297
Element.prototype.hasClassName = function (a) {
return new RegExp("(?:^|\\s+)" + a + "(?:\\s+|$)").test(this.className);
};
can any ine tell me how to define this element
Upvotes: 1
Views: 958
Reputation: 23863
JavaScript has a distinction between native objects
-- those things created by JavaScript and host objects
-- those things created by the browser for JavaScript to use.
The rules on how the two behave are quite different, but to summarize:
Element
is a host object, and under IE, doesn't follow the typical prototype behavior.
Upvotes: 0
Reputation: 74036
In modern browsers you could better rely on the classList
attribute:
el.classList.contains( 'myclass' ); // returns true or false
For older browser MDN lists a polyfill.
Upvotes: 3