File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Highlight the search keyword" Watch "Highlight the search keyword" New topic
Author

Highlight the search keyword

Soumya Manjunath
Ranch Hand

Joined: Nov 28, 2007
Posts: 34
Guys,

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
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

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
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
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.

Bill
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
Rancher

Joined: Jul 15, 2009
Posts: 377

Hey,

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.

Sean


I love this place!
Soumya Manjunath
Ranch Hand

Joined: Nov 28, 2007
Posts: 34
Thanks.Let me try that!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Highlight the search keyword