File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Highlight the search keyword Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Highlight the search keyword" Watch "Highlight the search keyword" New topic

Highlight the search keyword

Soumya Manjunath
Ranch Hand

Joined: Nov 28, 2007
Posts: 34

I'm developing a Search functionality in a page where in I need to highlight the search keyword criteria.
Could somebody please explain me how to achieve this/point me to good examples.

Thanks & Regards,<br />Soumya.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60739

Apply CSS styles to the highlighted text.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12756
Are you asking about how to highlight (display style) or how to locate the words in the text in the first place (parsing) in order to apply the style.

Soumya Manjunath
Ranch Hand

Joined: Nov 28, 2007
Posts: 34
Thanks for the reply Guys.

Yes Bill, I would like to know how to locate the words in the text and then how to highlight them.
Sean Clark

Joined: Jul 15, 2009
Posts: 377


I was thinking about doing the same thing, although I haven't got round to implementing it. I would use a Regular Expression to find the work you are searching for capture it and replace with the same text surrounded by some kind of css class: e.g.

Then add some style to highlight.


I love this place!
Soumya Manjunath
Ranch Hand

Joined: Nov 28, 2007
Posts: 34
Thanks.Let me try that!
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Highlight the search keyword
Similar Threads
Highlight the words in files( doc, excel, pdf etc) using java
Whizlabs SCWCD 1.4 Exam Simulator
XSLT problem
servlets and pdf...
Long just isn't long enough ..