この質問は少し2部構成です。まず、タイトルの質問。これが私が持っているものです:
// Report all of the parents
$(this).parents().each(function(i){
// Collect the parts in a var
var $crumb = '';
// Get the tag name of the parent
$crumb += "<span class='tagName'>"+this.tagName+"</span>";
// And finally, report it
$breadcrumbs.prepend($crumb);
});
残念ながら、これには実際の要素自体は含まれず、親のみが含まれます。「これと両親」のような言い方はありますか?
さて、2番目の質問。スタックに追加できなかった場合、その「this」機能を維持しながら、その関数の内臓を別の関数に分離するにはどうすればよいですか?それは次のようなものでしょうか:
// Function to report the findings
function crumble(e){
// Collect the parts in a var
var $crumb = '';
// Get the tag name of the parent
$crumb += "<span class='tagName'>"+this.tagName+"</span>";
// And finally, report it
$breadcrumbs.prepend($crumb);
};
$(this).parents().each(crumble());
よろしくお願いします!