 <p>You can try this, It will work for both example.</p> <pre><code>$('h1').each(function(){ var self = $(this); var p = self.text().split(' '); var html = self.html().replace(p[0], '&lt;span&gt;'+ p[0] +'&lt;/span&gt;'); self.html(html); }); </code></pre> <p>Check this <strong><a href="http://jsfiddle.net/6seeW/" rel="nofollow">Demo</a></strong></p>