How to remove special character from the class obtained from a text?

Asked

Viewed 29 times

0

I am using this code to pass the text of a label to class:

$('label').each(function() {
    const el = $(this);
    el.addClass( 'pay-' + el.text() );
});

However, I need to use words with accentuation, which ends up disabling.

<label for="P1386_ID_FORMA_MEIO_1" class="pay-Cartão">Cartão</label>

with I could remove the accentuation only of the created class?

  • https://answall.com/a/406366/112052

1 answer

1


You can normalize the string using an ES6 javascript function.

const textoNormalizado = el.text().normalize('NFD').replace(/[\u0300-\u036f]/g, '');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.