I've been searching, and I found this Question from stack overflow so I've been trying to make it work with my code, and I can't seem to get it to work.
html = '<li style="list-style:none;">';
cmnt = this.comment.replace(new RegExp( "(" + preg_quote( firsttext ) + ")" , 'gi' ), "<span class='cutecl'>$1</span>");
cmnt = cmnt.replace(new RegExp( "(" + preg_quote( secondtext ) + ")" , 'gi' ), "<span class='wincl'>$1</span>");
cmnt = cmnt.replace(new RegExp( "(" + preg_quote( thirdtext ) + ")" , 'gi' ), "<span class='failcl'>$1</span>");
html += cmnt;
html += '<br/><a href="http://www.youtube.com/userPage.php?author='+escape(this.author)+'">'+this.author+'</a>';
html += '<span class="label"> - '+(this.published.getMonth() + 1)+'/'+this.published.getDate()+'/'+this.published.getFullYear()+'</span>';
html += '</li>';
$('#comment').append(html);
and of course:
function preg_quote( str ) {
return (str+'').replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, "\\$1");
}
when I have
cmnt = this.comment.replace(new RegExp( "(" + preg_quote( firsttext ) + ")" , 'gi' ), "<span class='cutecl'>$1</span>");
cmnt = cmnt.replace(new RegExp( "(" + preg_quote( secondtext ) + ")" , 'gi' ), "<span class='wincl'>$1</span>");
cmnt = cmnt.replace(new RegExp( "(" + preg_quote( thirdtext ) + ")" , 'gi' ), "<span class='failcl'>$1</span>");
included in my code nothing appears when I want it to create that li, but if its gone, it works fine, any clue what I'm doing wrong? thanks in advance, ali
Here is a fiddle of the problem: http://jsfiddle.net/Yg8Qe/2/