I’m trying to insert a span around the first word in an H1 tag.
Unfortunately the tags can also be links and can include classes etc, eg:
-
Source =
<h1>This is a test</h1>Output =
<h1><span>This</span> is a test</h1> -
Source =
<h1 class="blah blah"><a href="#">This is a test<a/></h1>Output =
<h1 class="blah blah"><a href="#"><span>This</span> is a test<a/></h1>
Has anyone done this before in say jQuery?
Works for both “a” tag in it and plain text.
Demo