Is it possible to add a HTML element before a specific string using jQuery? For example, if I have:
<h4>Men's Basketball vs. Georgetown</h4>
And I would like to make it:
<h4>Men's Basketball <span class="team">vs. Georgetown</span></h4>
Can I do that with jQuery? I have tried to use a variety of options (:contains, prepend(), html(), pop(), etc. But none of them seem to work exactly right.
jsFiddle DemoAssuming that for every
h4you would like thevs.and what follows wrapped in a span, then you should iterate through each one, determine the location ofvs.in the string and then wrap it in a span.html:
<h4>Men's Basketball vs. Georgetown</h4>css:
.team{ color: red; }js: