脱jQuery~JavaScriptに支配されないための真の思考法~ findメソッド
Selectorの書いたので、今日は、jQueryのfineメソッドについて書く。
// jQuery var _$foo = $('#hoge').find('.foo'); // JavaScript var _foo = document.querySelectorAll('#hoge')[0].querySelectorAll('.foo');
// jQuery var _$foo = $('.hoge').find('#foo'); // JavaScript var _foo = []; document.querySelectorAll('.hoge').forEach(function(currentValue){ currentValue.querySelectorAll('.foo').forEach(function(currentValue){ _foo[_foo.length] = currentValue; }); });