jquery - Wrap text inside html tag -
i trying wrap text in inside <span>
tag using jquery. below code not working. please point out going wrong. please suggest better/different approach.
var mysearch = '(05/13/2012-11/13/2012)'; $('table:eq(0) tr:eq(1) th:contains("' + mysearch + '")').filter(function () { return this.html().replace('(05/13/2012-11/13/2012)', '<span class = "red"> (05/13/2012-11/13/2012)</span>'); });
this
in code dom element object doesn't have html
method, don't need filter
method, can use html
method.
$('table:eq(0) tr:eq(1) th:contains("' + mysearch + '")').html(function(_, html) { return html.replace('(05/13/2012-11/13/2012)', '<span class="red"> (05/13/2012-11/13/2012)</span>'); });
if content of th
equal mysearch
string, can use wrapinner
method:
$('table:eq(0) tr:eq(1) th').filter(function(){ return $.trim($(this).text()) === mysearch; }).wrapinner('<span class="red"></span>');
Comments
Post a Comment