すべての親要素の名前を取得するには?すべての親要素の名前を取得するより良い方法はありますか?
$(document).on('click', function(e){
var parents = $(e.target).parents().map(function(){
var $this = $(this),
$id = $this.prop('id') ? '#'+$this.attr('id') : '',
$class = $this.prop('class') ? '.'+$this.attr('class') : '';
return this.tagName.toLowerCase()+$id+$class;
}).get().join(" < ");
prompt('The path to the element, Luke:',parents);
});
FIDDLEを例とします。
EDIT:ニース!みんなありがとう! FIDDLEを更新しました。
あなたは別の方法は、すべての親を取得したいのはなぜ要素??あなたの道はうまくいかない? :\ – elboletaire
私のやり方でさえ常に良い方法があります;) –