Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

252
Views
Cambiar html de <p> sin cambiar <span>

Tengo un lapso dentro de un párrafo y quiero poder cambiar el texto del párrafo y el texto del lapso con los clics del botón. En este momento, cuando llamo a la función, el párrafo se actualiza pero el lapso desaparece.

 <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 answers
Answer question

0

Si cambia el HTML de la p principal, eliminará todo lo que contiene. Sin embargo, puede reestructurar su html para tener dos span dentro de la p y actualizar el texto de esos.

Aquí hay un ejemplo con #c como el primer intervalo y #b como el segundo:

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!