comparison default/node_modules/shoestring/src/dom/addClass.js @ 0:1d038bc9b3d2 default tip

Up:default
author Liny <dev@neowd.com>
date Sat, 31 May 2025 09:21:51 +0800
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1d038bc9b3d2
1 //>>excludeStart("exclude", pragmas.exclude);
2 define([ "shoestring" ], function(){
3 //>>excludeEnd("exclude");
4
5 /**
6 * Add a class to each DOM element in the set of elements.
7 *
8 * @param {string} className The name of the class to be added.
9 * @return shoestring
10 * @this shoestring
11 */
12 shoestring.fn.addClass = function( className ){
13 var classes = className.replace(/^\s+|\s+$/g, '').split( " " );
14
15 return this.each(function(){
16 for( var i = 0, il = classes.length; i < il; i++ ){
17 if( this.className !== undefined &&
18 (this.className === "" ||
19 !this.className.match( new RegExp( "(^|\\s)" + classes[ i ] + "($|\\s)"))) ){
20 this.className += " " + classes[ i ];
21 }
22 }
23 });
24 };
25
26 //>>excludeStart("exclude", pragmas.exclude);
27 });
28 //>>excludeEnd("exclude");