Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
160
rated 0 times [  165] [ 5]  / answers: 1 / hits: 57809  / 13 Years ago, thu, december 22, 2011, 12:00:00

Let's say I have many of these in my content div : <cite class=fn>blabla</cite>



How can I check every cite tag's content (in this case: blabla) with class fn to see if it equals to sometext then change it's color to red ?



Very simple.


More From » jquery

 Answers
31
$('cite.fn:contains(blabla)').css('color', 'red');


Edit: though that will match blablablabla as well.



$('cite.fn').each(function () {
if ($(this).text() == 'blabla') {
$(this).css('color', 'red');
}
});


That should be more accurate.



Edit: Actually, I think bazmegakapa's solution is more elegant:



$('cite.fn').filter(function () {
return $(this).text() == 'blabla';
}).css('color', 'red');;

[#88421] Wednesday, December 21, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elainaw

Total Points: 83
Total Questions: 99
Total Answers: 111

Location: South Sudan
Member since Sat, May 27, 2023
1 Year ago
;