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 td elements One of my defined classes is now I just wanted to apply a class on those td elements 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

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -