Menu

[r4]: / trunk / mere / dom.js  Maximize  Restore  History

Download this file

33 lines (28 with data), 934 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
if (!this.mere) {var mere = {}}
mere.dom = {
classRegex: function(className) {
return new RegExp("(\\s|^)" + className + "(\\s|$)");
},
hasClass: function(element, className) {
if (!element) { return; }
var reg = this.classRegex(className);
return element.className.match(reg);
},
addClass: function(element, className) {
if (!element) { return; }
if (this.hasClass(element, className)) { return; }
var newClasses = element.className + ' ' + className;
element.className = this.trim(newClasses);
},
removeClass: function(element, className) {
if (this.hasClass(element, className)) {
var reg = this.classRegex(className);
var newClasses = element.className.replace(reg, ' ');
element.className = this.trim(newClasses);
}
},
//duplicated from str.js
trim: function(str) {
return str.replace(/^\s*|\s*$/g,"")
},
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.