• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to highlight word in html

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In content only, And no its not a home assignment.
 
reply
    Bookmark Topic Watch Topic
  • New Topic