penguinrob
penguinrob

Reputation: 1459

Highlight specific words with CSS/JavaScript

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.

Upvotes: 2

Views: 2489

Answers (3)

Steve Wellens
Steve Wellens

Reputation: 20620

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

Upvotes: 0

cellcortex
cellcortex

Reputation: 3176

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>') );
});

Upvotes: 2

stslavik
stslavik

Reputation: 3028

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.

Upvotes: 0

Related Questions