Ho bisogno di passare un elemento a una funzione e poi abbinare quell'elemento specifico mentre attraversi il genitore. La presa (per qualcuno che non sa come me) è che questo elemento non ha un ID. Nel seguente esempio, voglio che ogni elemento per accendere rosa tranne quello cliccato che dovrebbe diventare giallojQuery - come verificare se due elementi sono uguali?
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));
});
Vedi http://stackoverflow.com/questions/4441135/how-to-compare-two-doms-or-dom-nodes-in-general –