JQuery and special characters in attribute

Total Post:128


 2184  View(s)
Rate this:

In my jquery script I need to dynamically translate some content, so part of such function is

$('#password').attr('placeholder', 'Contraseña');

where I tried to change placeholder attribute to text Contraseña.

Unfortunatelly, jquery shows text Contraseña

What does a trick to force jquery to show correct decoded text?

  1. Re: JQuery and special characters in attribute

    You have to escape special characters using JavaScript syntax, not HTML syntax.

    $('#password').attr('placeholder', 'Contrase\u00f1a');

    Personally I'd use .prop() instead of .attr() too, though both should work here.

      Modified On Mar-31-2018 06:40:46 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.