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

263
Vistas
Changing html of <p> without changing <span>

I have a span inside a paragraph and want to be able to change the paragraph text and the span text from button clicks. Right now when I call the function the paragraph is updated but the span disappears.

<p id = "a">Some text to change <span id = "b" onmouseenter="test()">click!</span></p>
function test() {
   $("#a").html("New text here");
   $("#b").html("click again!");
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you change the HTML of the parent p, it will remove everything inside it. However, you can restructure your html to have two spans inside the p and update the text of those.

Here's an example with #c as the first span and #b as the second:

function test() {
   $("#c").text("New text here ");
   $("#b").text("click again!");
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<p id = "a"><span id = "c">Some text to change </span><span id = "b" onmouseenter="test()">click!</span></p>

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