Ciao,
ho dei testi racchiusi da // // che voglio evidenziare con una particolare classe CSS. Ad esempio
// Parla tizio // non è possibile
// Parla caio // ti dico che è vero
cercando in rete ho trovato questa funzione (l'ho modificata leggermente) che sfrutta le espressioni regolari, ma sbaglio qualcosa perché si il testo viene evidenziato, ma diventa sempre l'ultimo "parla caio".
dove sbaglio?
function highlight () {
var $query = "//(.*)//";
var re = new RegExp($query, 'gi');
var targetHtml = $('#songs').html();
if(re.test(targetHtml)) {
var matches = targetHtml.match(re);
for (i=0; i<matches.length; i++) {
$('#songs').html(targetHtml.replace(re, '<span class="higher">'+matches[i]+'</span>'));
}
}
var targetHtml = $('#songs').html();
}
$(document).ready(function() {
highlight();
});