私は関数に要素を渡してから、その特定の要素を親を横断しながら照合する必要があります。キャッチ(私のような無知な誰かのために)は、この要素にidがないことです。次の例では、私はそれがtrueを返すことはありませんjQueryのオブジェクトを比較jQuery - 2つの要素が同じかどうかを確認する方法?
function colorize(element) {
element.parent().find('span').each(function() {
if ($(this)===element) { // the problem is this is always false
$(this).css('background','yellow');
} else {
$(this).css('background','pink');
}
});
}
$('span').click(function() {
colorize($(this));
});
はhttp://stackoverflow.com/questions/4441135/how-to-compare-two-doms-or-dom-nodes-in-general –