今回はjQueryオブジェクトに定義されたメソッドの説明が中心となります。前回のようなjQueryの特徴的な部分と違ってアクロバティックな感じではないので,
また,
attr()
0172: attr: function( name, value, type ) {
0173: var options = name;
0174:
0175: // Look for the case where we're accessing a style value
0176: if ( name.constructor == String )
0177: if ( value == undefined )
0178: return this.length && jQuery[ type || "attr" ]( this[0], name ) || undefined;
0179:
0180: else {
0181: options = {};
0182: options[ name ] = value;
0183: }
0184:
0185: // Check to see if we're setting style values
0186: return this.each(function(i){
0187: // Set all the styles
0188: for ( name in options )
0189: jQuery.attr(
0190: type ?
0191: this.style :
0192: this,
0193: name, jQuery.prop( this, options[ name ], type, i, name )
0194: );
0195: });
0196: },
0197:
attrメソッドは,
第1引数nameのみが渡されてそれが文字列の場合
実際に属性をセットするのは186行目からで,
また,
css()
0198: css: function( key, value ) {
0199: // ignore negative width and height values
0200: if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )
0201: value = undefined;
0202: return this.attr( key, value, "curCSS" );
0203: },
0204:
CSSのプロパティを設定するメソッドです。 内部的には先ほどのattrメソッドを呼び出しています。widthまたはheightで負の値を設定しようとした場合は,
また,
text()
0205: text: function( text ) {
0206: if ( typeof text != "object" && text != null )
0207: return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
0208:
0209: var ret = "";
0210:
0211: jQuery.each( text || this, function(){
0212: jQuery.each( this.childNodes, function(){
0213: if ( this.nodeType != 8 )
0214: ret += this.nodeType != 1 ?
0215: this.nodeValue :
0216: jQuery.fn.text( [ this ] );
0217: });
0218: });
0219:
0220: return ret;
0221: },
0222:
206行目がパラメータが渡された時の処理で,
211行目からはパラメータがない場合の処理で,
wrapAll()
0223: wrapAll: function( html ) {
0224: if ( this[0] )
0225: // The elements to wrap the target around
0226: jQuery( html, this[0].ownerDocument )
0227: .clone()
0228: .insertBefore( this[0] )
0229: .map(function(){
0230: var elem = this;
0231:
0232: while ( elem.firstChild )
0233: elem = elem.firstChild;
0234:
0235: return elem;
0236: })
0237: .append(this);
0238:
0239 return this;
0240: },
0241:
wrapAllメソッドは,
このメソッドを実行するにはすくなくとも1つ以上の要素が必要なので,
ここは少し分かりにくいかもしれませんが,
wrapInner()
0242: wrapInner: function( html ) {
0243: return this.each(function(){
0244: jQuery( this ).contents().wrapAll( html );
0245: });
0246: },
0247:
wrapInnerメソッドは,
wrap()
0248: wrap: function( html ) {
0249: return this.each(function(){
0250: jQuery( this ).wrapAll( html );
0251: });
0252: },
0253:
wrapメソッドは,