How can I manage subindices in the messages I want to print to the user in javascript

1

Good afternoon,

I have a doubt, in JavaScript code if I want to print to the user a message that says square meters but that "squares" in a superindice of the letter m, is it possible?

This is the example of how it should look:

Thank you very much!

    
asked by Jairo Cuartas 28.09.2017 в 00:59
source

2 answers

1

If by ... show a message to the user ... you refer to javascript through a alert you can use characters < strong> Unicode , for example:

alert("La habitación tiene 9 m\xB2 de superficie");

If it is through HTML you can indicate it by means of the superscript tag in other mentioned answers or also by HTML entities or representation hexadecimal , for example:

  • Superscript element ( < sup > ): "The stadium Santiago Bernabéu has 7140 m 2 surface"
  • HTML entities ( & 2; ): "The Santiago Bernabéu stadium has 7140 m² of surface"
  • Hexadecimal representation ( & # xB2; ): "The Santiago Bernabéu stadium has 7140 m² of surface"

and possibly some more ...

    
answered by 28.09.2017 / 03:28
source
1

It is not necessary to have a high complexity code in Javascript, with which you use the superscript tag <sup></sup> in some Javascript function that inserts HTML, as innerHTML

<p> El área del cuadrado es de 35 m<sup>2</sup>

I imagine that it is the position that you occupy, because for subindex it would be down and that is used for another type of mathematical syntax, I leave you the example of subscript <sub></sub>

<p>3x<sub>3</sub>y<sub>5</sub>z<sub>2</sub></p>
    
answered by 28.09.2017 в 01:05