2

Is it possible to highlight (or do something to) specific words, or regular expressions?

I'm going for a no-javascript solution here, but it might not be possible.

2
  • Do you need to handle text that crosses element boundaries? For example, searching for "foobar" in <p>foo<b>bar</b></p>? Commented Aug 8, 2011 at 22:57
  • @Tim Down, no, it's all just in a big div with no formatting. Commented Aug 8, 2011 at 23:02

3 Answers 3

2

You will need JavaScript to do this. I recommend using a strong tag rather than span but either will work. This will replace all first words. You can replace the ^\w with whatever is meaningful.

$('a').each(function() { var me = $(this); me.html( me.text().replace(/(^\w+)/,'<strong>$1</strong>') ); }); 
Sign up to request clarification or add additional context in comments.

Comments

0

Best you can hope for is encapsulating the words in a span with a class to do some sort of highlighting. You could do this server side based on search results by using a simple regex compare to replace the searched for string with that string again wrapped with a span. It is not possible, so far as I know, to do this solely with CSS.

Comments

0

No it's not, you would have to use spans.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.