Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
Bold the selected text

I have an HTML5 file and I am trying to make an app like Google Docs using create-electron-app.

I have a textarea tag for the input, and I am trying to bold the text the user has selected. I have the getSelectedText() function working and It is returning a string like expected, but I need to bold that text inside of the textarea. If you have used Google Docs you should know what I mean.

Here is the code:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Make word documents!</title>
    <link rel="stylesheet" href="index.css" />
  </head>
  <body>
    <textarea class="userInput"></textarea>

    <input type="button"
    value="Bold" 
    onmousedown="bold()">

    <script>

function getSelectedText() {
    if (window.getSelection) {
        return "" + window.getSelection();
    } else if (document.selection && document.selection.type == "Text") {
        return document.selection.createRange().text;
    }
    return "";
}


      function bold() {
        var userInput = getSelectedText();
        // userInput.style.fontWeight = "bold";

        // print the type of the userinput variable
        console.log(typeof userInput);
        
      }
    </script>
  </body>
</html>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

QuestionSign in to vote

0

Sign in to vote

User1937363675 posted

Hi Francis

Actually I think you should use "span" instead of "textarea",because according to some material,Web Editor all almost use span.I wrote a short example for you,hope that can help you!

--------------

<html>
<head>
<script language="javascript">
function test(e)
{
   mytext.innerHTML="<b>"+mytext.innerText+"</b>";
}


</script>
</head>
<body>
<span contenteditable id="mytext" style="height:200;width:95%;border:1px solid black">
HTML Editor
</span>
<input type="button" value="Bold" onclick="test()" />
</body>


</html>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda