aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes How to highlight word in html 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 "How to highlight word in html" Watch "How to highlight word in html" New topic
Author

How to highlight word in html

rahul taiwala
Greenhorn

Joined: Feb 06, 2011
Posts: 12
How to highlight all words in html one by one using javascript?
Any idea how to proceed?
I have tried a lot of things but I get confused when it comes to deeply nested tags.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41863
    
  63
What do you have now, and where, exactly, are you having problems to proceed?


Ping & DNS - my free Android networking tools app
rahul taiwala
Greenhorn

Joined: Feb 06, 2011
Posts: 12
I am using this code to highlight each word one by one in a html document, but it is not that good method.
And It faces some problem for some words, if white space between two word is more than one, or if return character is encountered more than once

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

That's a lot of code to something as simple as highlighting. What are the requirements? How are the words identified for highlighting? What does highlighting even mean?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
rahul taiwala
Greenhorn

Joined: Feb 06, 2011
Posts: 12
I need to highlight-meaning change the background color of each and every word in the html document one after another using javascript.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

That's still not enough of a description for us to help. What constitutes a word? And where? In attributes? Content only? You seem to have some animation code in there; your description doesn't mention animation.

This seems like an academic exercise. Is it homework?

Why aren't you using jQuery to make this all much easier?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41863
    
  63
There's code to deal especially with IE4 Seriously, wherever you got that code from, never again go there.
rahul taiwala
Greenhorn

Joined: Feb 06, 2011
Posts: 12
Suppose I have Paragraph tag which contains some string like-


Here, word is a sequence of character separated by white space, so here words are-A,friendly,place,for,programming,greenhorns,Big,Moose,Saloon
Now I need to change the background color of each word starting from "A" to "Saloon", one by one.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61218
    
  66

Please answer my other questions.

So, the first step is to push the keyboard away, and write down how you would do this step by step. You should not write a single line of code until you have this in place.
rahul taiwala
Greenhorn

Joined: Feb 06, 2011
Posts: 12
In content only, And no its not a home assignment.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to highlight word in html