2012-03-29 8 views
0

HTML:私はIEでその上映をにconsole.logを行う際に、ここでいただきました奇数jqueryの内の最初の子

 <div class="wrapper" style="display:none"> 
      <div class="panel"></div> 
     </div> 

JSのCALL

var element = $(".wrapper"); 
element.toggle().children(":first").custom(); 
$(".wrapper .panel").custom(); 

CUSTOM jQueryのMETHOD

$.fn.custom = function() { 
     return this.each(function() { 
      console.log(" this = ", this); 
       // do something to each dom element. 
     }); 
    }; 

パネル要素への最初の呼び出しは、

[オブジェクトHTMLGenericElement]

が、これがあると、最初の呼び出しは、あなたが使用する必要があります[objectHTMLDIVElement]

答えて

1

も持っているか、なぜ2回目の呼び出しは、[objectHTMLDIVElement]

としてそれを示しています機能の代わりにthisの代わりに$(this)を使用してください。

return this.each(function() { 
    console.log(" this = ", $(this)); 
    // do something to each dom element. 
}) 

以外にも、私はクローム、サファリ、Firefoxでthisをチェックし、どこでも、私は<div>要素

+3

それはなぜですか? –

+0

まだ同じ結果が返ってきます – Chapsterj

+0

@SKS、[基本的なプラグインオーサリング](http://docs.jquery.com/Plugins/Authoring)ページ – Starx

0

このJSFiddleによるとを受け付けており、それらは両方とも[オブジェクトHTMLDivElement]として記録されます。

IE9(バージョン9.0.8112.16421 64ビット)でテスト済みです。

関連する問題