・jsファイル
---------------------------------------------------------------------------
$("#button").click(function() {
$.ajax({
type: 'GET',
url: 'file.html',
dataType: 'html',
success: function (data) {
console.log($('div', $(data)));
},
});
});
---------------------------------------------------------------------------
・file.html
---------------------------------------------------------------------------
<div class="test">test</div>
---------------------------------------------------------------------------
ちなみに、以下のようにdiv.testをdivでさらに囲んでやると取得することが出来るようです。
---------------------------------------------------------------------------
<div class="wrap">
<div class="test">test</div>
</div>
---------------------------------------------------------------------------
jQueryのバージョンは1.11、ブラウザはSafari 7.05を使用しています。
どのようなスクリプトで最上層の要素を取得することができるのでしょうか?
$(function() { $("#button").click(function() { $.ajax({ type: 'GET', url: 'file.html', dataType: 'html', success: function (data) { console.log($(data)); }, }); }); });