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

144
Views
¿Cómo reemplazo el texto dentro de un párrafo dentro de un elemento div?

Necesito configurar el texto dentro de un Párrafo que está dentro de un elemento DIV dinámicamente. Conozco el divID y puedo obtener el div por id usando get document.getElementById(divID) Esto devuelve lo siguiente:

 <div id="mynote72031" class="mydiv" ondrop="drop(event,this.id)" ondragover="allowDrop(event)" style="cursor: move; display: block; top: 19px; left: 19px; width: 375px;"> <a style="top:0px; right:5px; position:absolute; color:#F00" href="javascript:;" onclick="hideElement(this)">X</a> <p id="noteContent1" ondblclick="editContent(this)">Note Number: 1</p> </div>

La función debería verse así:

 function updateNote(divID, paragraphInnerHTML) { var updateNoteP = document.getElementById(divID); //Update Paragraph inside the DIV here }

Tenga en cuenta que la identificación del párrafo siempre es noteContent1

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Hay 2 formas de cambiar el texto dentro de la etiqueta HTML

 function updateNote(divID, paragraphInnerHTML) { var updateNoteP = document.getElementById(divID); //Update Paragraph inside the DIV here let $targetEle = updateNoteP.childNodes[1] // use innerHTML $targetEle.innerHTML = paragraphInnerHTML // or textContext $targetEle.textContent = paragraphInnerHTML }
about 4 years ago · Juan Pablo Isaza Report

0

Puede usarNode.lastChild para acceder a la etiqueta p , ya que es el último elemento dentro de la etiqueta div

 function updateNote(divID, paragraphInnerHTML) { var updateNoteP = document.getElementById(divID); //Update Paragraph inside the DIV here let pElement = updateNoteP.lastChild; pElement.innerHTML = paragraphInnerHTML; }
about 4 years ago · Juan Pablo Isaza Report

0

Bastante cerca con su nombre de variable, esto supone que es html lo que desea usar. Si es solo una cadena, puede usar updateNoteP.innerText en su lugar

Si pasa pID como "noteContent1", esto cambiará el contenido de la P

 function updateNote(pID, paragraphInnerHTML) { var updateNoteP = document.getElementById(divID); // check that element is found if (updateNoteP) { // update inner html updateNoteP.parentElement.children[1].innerHTML = paragraphInnerHTML } }
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!