In the HTML markup, you can write & ndash or & mdash.

But if I, for example, output some text to input with js, then the mnemonic does not work and is perceived simply as a set of characters:

$('button').click(function() { $('input').val('Москва - столица России'); }); 

How to make a long dash in such a text, outputted with the help of js?

  • one
    @ElenaSemenchenko, notice that the text is inserted into the input, in it the mnemonics do not work. You just need to use the long dash symbol - Grundy
  • @Grundy, as usual not attentive!) Sorry - HamSter

2 answers 2

 $('button').click(function() { $('input').val('Москва \u2013 столица России'); }); 
  • 2
    or directly symbol: - Grundy
  • it is not necessary to single it out in a separate line, you can even so 'Москва \u2013 столица России' - Grundy

In order of perversion (well, or if the required string has already come from somewhere with encoded html entities):

 var s = 'Москва — столица России'; var d = document.createElement('div'); d.innerHTML = s; console.log(d.innerText); // Москва — столица России 
  • This is all due to the lack of a built-in function htmlDecode - Grundy