以下は、2つのdivのコンテンツを交換するために反復しているループです。
$("#itemsRows ul").each(function () {
var $this = $(this);
$("#wrap-ajax ul").each(function () {
// How to get #itemsRows ul input element?
});
});
回答:
回答№1は2使用することによって find
または children
に $this
:
$("#itemsRows ul").each(function () {
var $this = $(this);
$("#wrap-ajax ul").each(function () {
var theInput = $this.find("input");
// Or
var theInput = $this.children("input");
});
});
...子孫要素が必要かどうかに応じて(質問が示唆するように; find
)、または直接の子(children
)。
あなたの内側のループの反復関数は、それを作成したコンテキストを閉じます。 $this
変数なので、内部のイテレータ関数の内部にいるとしても、 $this
特定の #itemsRows ul
外側のループの要素。
閉鎖の詳細(ブログ): 閉鎖は複雑ではない