chandan
chandan

Reputation: 1574

jQuery: Adding <span></span> to text inside a <li>

firstly here the fiddle

I want to add a <span class="Text"></span> to text ''RSS' inside an <li>.

HTML Code:

    <ul>
    <li class="hasToolTip"> RSS Feeds</li>
    </ul>

Upvotes: 2

Views: 803

Answers (1)

Milind Anantwar
Milind Anantwar

Reputation: 82241

You can find the li that contains text RSS. and then use .html() call back function to replace the each occurrence of RSS with span wrapped around it:

$("li.hasToolTip:contains('RSS')").html(function(_, html) {
  return html.replace(/(RSS)/g, '<span class="Text">RSS</span>');
});

Working Demo

Upvotes: 3

Related Questions