• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to highlight word in html

 
rahul taiwala
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you have now, and where, exactly, are you having problems to proceed?
 
rahul taiwala
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
rahul taiwala
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's code to deal especially with IE4 Seriously, wherever you got that code from, never again go there.
 
rahul taiwala
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In content only, And no its not a home assignment.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic