Question

$('table.listings td:contains("You")').each(function(){
 $(this).children('td:nth-child(2)').addClass('highlighted');
});

J'ai plusieurs table.listings sur la page, mais celui qui contient « Vous » est sélectionné et je veux addClass highlighted à la 2e cellule dans chaque ligne, mais le code ci-dessus ne fonctionne pas comme je m'y attendais.

Était-ce utile?

La solution

$('table.listings:contains("You") td:nth-child(2)').addClass("highlight");

Autres conseils

$('table.listings :contains("You")').each(function(){
 $(this).children('td:nth-child(2)').addClass('highlighted');
});

Essayez ceci:

$('table.listings td:contains("You")').each(function(){
    $("td:nth-child(2)", $(this).parent().parent().get(0)).addClass('highlighted');
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top