liが「Thing」と言っている場合は追加したいのですが、「Things」と言っている場合は追加しません。それは可能:contains
ですか?
$("ul li:nth-child(2):contains('Thing')").append("foo");
not関数があります:
$("ul li:nth-child(2):contains('Thing')").not(':contains("Things")').append("foo");
Thing
要素にテキストコンテンツが正確に含まれている場合に要素を選択する場合は、次のfilter
方法を使用できます。
$("ul li:nth-child(2)").filter(function(){
return $(this).text().trim() === 'Thing'
}).append("foo");
コードを少し圧縮するのに役立つ:not()セレクターもあります。
だからそれは
$("ul li:nth-child(2):contains('Thing'):not(:contains('Things'))").append("foo");
フィドルの小さな例。