javascript - Apply CSS on matching text -
I'm trying to apply the square where the text matches the sibling elements is.
I have some condition:
I have a table with several rows based on data obtained through the database in
tdelements One of my defined classes is now I just wanted to apply a class on thosetdelements where the text of this element matches any other.
So that would be, the code of TD is equal to the square of html / text .
I tried:
$ ('# table' & gt; tr '' ('Td [class ^ = "customtd" ] '). Each (function () {if ($ (this) .html () .tim () == $ (this) .siblings (' td ') .html (). Trim ()) {$ (this ) .addClass ('active');} and {$ (.) .removeClass ('active');}});
You must iterate over each brother td (or use filter ), check for a text match, then the class Add:
$ ('# table tbody & gt; tr'). ('Td [class ^ ("=" Customtd "]'). Each (function () {var text = $ (This) .text (); .text () == text;}) AddClass ("active");});
Comments
Post a Comment