JQUERY AND SPECIAL CHARACTERS IN ATTRIBUTE

Ashish Pandey

Total Post:128

Points:898
Posted by  Ashish Pandey
C# 
C#
 1699  View(s)
Ratings:
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. Jeet Verma

    Post:110

    Points:776
    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!