comparison default/node_modules/shoestring/src/dom/attr.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 * Get the value of the first element of the set or set the value of all the elements in the set.
7 *
8 * @param {string} name The attribute name.
9 * @param {string} value The new value for the attribute.
10 * @return {shoestring|string|undefined}
11 * @this {shoestring}
12 */
13 shoestring.fn.attr = function( name, value ){
14 var nameStr = typeof( name ) === "string";
15
16 if( value !== undefined || !nameStr ){
17 return this.each(function(){
18 if( nameStr ){
19 this.setAttribute( name, value );
20 } else {
21 for( var i in name ){
22 if( name.hasOwnProperty( i ) ){
23 this.setAttribute( i, name[ i ] );
24 }
25 }
26 }
27 });
28 } else {
29 return this[ 0 ] ? this[ 0 ].getAttribute( name ) : undefined;
30 }
31 };
32
33 //>>excludeStart("exclude", pragmas.exclude);
34 });
35 //>>excludeEnd("exclude");