Voglio selezionare un gruppo di span
in un div
cui CSS contiene un particolare colore di sfondo. Come ottengo questo?
se capisco correttamente la domanda, il selettore [attribute=value]
non funzionerà perché non contiene un attributo “background-color”. puoi testarlo rapidamente per confermare che non corrisponderà a nulla:
$('#someDiv span[background-color]').size(); // returns 0
dato:
// css .one, .two { background-color: black; } .three { background-color: red; } // html test one test two test three
ecco un frammento che funzionerà :
$('div#someDiv span').filter(function() { var match = 'rgb(0, 0, 0)'; // match background-color: black /* true = keep this element in our wrapped set false = remove this element from our wrapped set */ return ( $(this).css('background-color') == match ); }).css('background-color', 'green'); // change background color of all black spans
Usa il selettore dell’attributo [attributo = valore] per cercare un determinato valore di attributo.
#id_of_the_div span[background-color=rgb(255,255,255)]