jQueryを使ってテキストノードのみを抽出する。
// テキストノードのみを抽出して返す
function getTextNode ($target, str) {
var nodes = $target
.contents()
.filter(function () {
return this.nodeType === 3 // テキストノードか否か
&& /\S/.test(this.data) // 空白か否か
&& $.inArray($(this).parent(), $target) // 直下か否か
&& (typeof str === 'undefined' || str === this.nodeValue); // 文字列の指定がある場合
});
return nodes;
}