jQueryでドキュメントのルート要素を選択する方法は?
以下は、jQueryを使用してドキュメントのルート要素を選択する方法です。
$(document)
を使用する方法:
$(document).ready(function(){
var rootElement = $(document).children().first();
console.log(rootElement);
});
$(document.documentElement)
を使用する方法:
$(document).ready(function(){
var rootElement = $(document.documentElement);
console.log(rootElement);
});
両方の方法は同じ結果を返します。