tags:

views:

475

answers:

2

For example, I have the HTML...

<span class="userscontentname">Test</span>
<span class="userscontentname">Testman</span>

then I have the jQuery...

  if ($("#userlist_"+search_id+" > span.userscontentname:contains("+search_text+")").length > 0) {
   $("#userlist_"+search_id).show();
   $("#userlist_"+search_id+" > span.userscontentname:contains("+search_text+")").css("font-weight", "bold");
  }

If the search_text is Test...

It will bold both Test and Testman completely. How do I make it so that it will only bold Test leaving out man in the second span?

Thanks!

+2  A: 

http://www.jquery.info/spip.php?article50

Jonathan
+1 - that one seems to have better features than the one on my answer.
Kobi
+1  A: 

Take a look on the jQuery highlight plugin.

Just change the CSS to

.highlight { font-wight: bold; }
Kobi
Any way to do this without a plugin by any chance?
Chris
@Chris - sure. just look at the source code of the plugin, it does exactly what you need and isn't too long. No point of doing that, of course, it is ready for use... http://johannburkard.de/resources/Johann/jquery.highlight-3.js
Kobi