I'm trying to replace each letter of a div with many "span".
This code works except for letters with accents like "é". Can you help me please?
$('h2').each(function(){
$(this).html($(this).text().replace(/(\w)/g, "<span>$&</span>"));
});
You can try with following regex:
/([^\x00-\x80]|\w)/g
\w
doesn't include diacritic symbols so you need to specify an unicode range, like this
/[a-z\u00C0-\u00F6\u00F8-\017E]/gi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With