1. Home
  2. Computing & Technology
  3. JavaScript

Highlighting Selected Words

2. Get the Script

Join the Discussion

Questions? Comments?

More of this Feature

Sample

To be able to highlight the selected words on one of your web pages you first need to select the code from the text box below (there is a highlight all button beneath it to make this easier) and copy it into a file called hilite.js.

You next attach the script into your web page that you wish to be able to highlight any of the words on by adding the following code into the head section of your page.

<script type="text/javascript" src="hilite.js">
</script>
<style>
.hl {color:#f00;background-color:#ff0;font-weight:bold;}
</style>

You can of course put the style command into your own external stylesheet if you have one and can use whatever colour scheme that you like for the highlighted text colour scheme defined by the .hl line in your stylesheet.

With this code attached into the head of your web page you can then pass a query string indicating the words to be highlighted using whatever method that you like to generate the ?hilite= on the end of the address of your page.

Explore JavaScript
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.