Web Analytics Made Easy -
StatCounter Text highlighting in JS - CodingForum

Announcement

Collapse
No announcement yet.

Text highlighting in JS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Text highlighting in JS

    Just wondering if anyone here knows how to let the user select some text on a webpage (using the mouse) and have the JS change the style of the selected text fragment (eg. yellow background colour of the text). I'm particularily interested in an implementation that would work in NS/Mozilla.

    Any hints, suggestions or examples would be greatly appreciated.

  • #2
    Changing styles of text

    <style type="text/css">
    span.a {background-color:red; color:white;}
    span.b {background-color:white; color:red;}
    </style>

    <span class="a" onmouseover="this.className='b'" onmouseout="this.className='a'">your text</span>

    The "N" in className must be capitalized.

    Good Luck
    Master Newbie http://dwightstegall.com/

    Comment

    Working...
    X