Heejin
Heejin

Reputation: 4581

Highlighting search results do not work in some situation

I am very new in Javascript.

I want to make some basic stuffs that can be used in my future project.

One of the stuffs I need is highlighting some keywords.

http://jsfiddle.net/4wMjP/1/

You can find the working code for the functionality at the above link.

The problem is if I uncomment the following line in HTML,

<!-- <h1>Polls show Romney surging ahead of Gingrich in Florida</h1> -->

The functionality does not work.

What is the problem and how to solve the problem?

Upvotes: 0

Views: 37

Answers (1)

mrtsherman
mrtsherman

Reputation: 39902

You can't have block level elements inside a paragraph tag.

<p><h1></h1></p> <!-- Not valid HTML! -->

If you want the heading to be inside the <p> and searchable then change the <p> to a <div>

http://jsfiddle.net/4wMjP/2/

Upvotes: 2

Related Questions