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

229
Vistas
How to change the color of the text after pressing the button in HTML - WKWebview Swift?

I've created a local HTML page and I can make changes to the textArea with the evaluateJavaScript function.

Everything works fine, but when I click the color change button, the color of the words in the whole textArea changes.

I just want to change the color of the words written after the button is pressed. Like Rich Text Editors.

Any idea about that ?

        //this is script functions and working fine
         <html>
<head>
    <meta charset="utf-8">
    <style>
        #textarea {
          background-color: #000000;
          color: #666666;
          padding: 1em;
          border-radius: 10px;
          border: 2px solid transparent;
          outline: none;
          font-family: "Heebo", sans-serif;
          font-weight: 500;
          font-size: 16px;
          line-height: 1.4;
          width: 200px;
          height: 233px;
        }
        
        #textarea:hover {
          cursor: pointer;
          background-color: #eeeeee;
        }
        
        #textarea:focus {
          cursor: text;
          color: #111111;
          background-color: #334455;
          border-color: #333333;
        }
        </style>
    
   </head>
   <body>
       <textarea id="textarea" placeholder="Enter a message..."></textarea>
       <script>
           
         function changeBackgroundColor(colorText) {
            document.body.style.background = colorText;
         }
           
         function changeTextColor() {
             
            var element = document.getElementById("textarea")
            element.style.color = "#FF0000";
            
         }
         </script>
   </body>

and this is WKWebView function:

evaluateJavaScript("changeTextColor()", completionHandler: nil)
almost 4 years ago · Santiago Trujillo
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