Skip to content
Advertisement

Changing colour of substring in Thymeleaf table cell not working

I am rewriting old legacy system written in PHP/HTML into Java/SpringBoot/Thymeleaf. In the old system, there is table displaying search result. In the column “Sentence” I call this function in order to highlight search keywords inside the sentence string.

JavaScript

Example: seach keyword is “Macron” and the sentence queried from database is “Emmanuel Macron meets Angela Merkel on Friday to discuss refugee crisis.” So “Macron” substring of the sentence has yellow colour.

Now I am trying to do the same thing in Thymeleaf so I wrote this Java method:

JavaScript

In my Thymeleaf template I call the method:

JavaScript

And to CSS, I added the style:

JavaScript

But it does not work. Colour of the substring is not changed though tag was added to the substring. Does anybody knows what the problem is please?

Thank you


EDIT:

I changed my style to:

JavaScript

and Java method to:

JavaScript

EDIT 2:

I realized that I don’t need CSS style at all as I want my characters to have black colour. So I changed my Java method to:

JavaScript

But if you want to change characters colour, use the approach from the first EDIT section.

Advertisement

Answer

I tried out your case and it works fine for me in both Chrome and Firefox. I think we need to elaborate your CSS. If the mark is indeed added to the html content of the td then something is going on with your CSS. You may have a look in the developer tools of your browser. (Usually invoked via F12) Find the misbehaving mark in your td and Elaborate the Style-Sheet attributes that actually are applied. Maybe some !important attribute elsewhere in the code overrides your settings.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement