Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
Reemplazar cadena dentro de la etiqueta html anidada en javascript

Quería reemplazar el contenido del texto, incluidas sus etiquetas. A continuación se muestra el código de muestra:

 <h1>JavaScript Strings</h1> <h2>The replace() Method</h2> <p>replace() searches a string for a value, and returns a new string with the specified value(s) replaced:</p> <p id="demo"><ul><li>Visit Microsoft!</li></ul> <ul><li>The following required data are either missing, have errors, or are not being properly saved. Ensure the data are correct and then press 'Save' on the indicated tab.<ul><li><a id='dataMissingHide95'>Items missing from the Sources of Funds tab (EXPAND)</a><a id='dataMissingShow95' style='display:none;'>Items missing from the Sources of funds tab (COLLAPSE)</a><ul id='itemsMissingShow95' style='display:none;'><li><a id='dataMissingHide92'>Transaction information (EXPAND)</a><a id='dataMissingShow92' style='display:none;'>Transaction information (COLLAPSE)</a><ul id='itemsMissingShow92' style='display:none;'><li>Investment experience (For any investment type checked, number of years must be selected.)</li></ul></li></ul></li><li><a id='dataMissingHide91'>Items missing from the Transaction Disclosures tab (EXPAND)</a><a id='dataMissingShow91' style='display:none;'>Items missing from the Transaction Disclosures tab (COLLAPSE)</a><ul id='itemsMissingShow91' style='display:none;'><li> Please answer the questions below on the Transaction Disclosures page and save the Transaction Disclosures page.<ul><li>Explain in detail why this transaction is in the best interest of your client</li></ul></li></ul></li></ul></li></ul></p> <script> let text = document.getElementById("demo").innerHTML; document.getElementById("demo").innerHTML = text.replace("<ul><li>Visit Microsoft!</li></ul>", "W3Schools"); </script>

Soy nuevo en JS ... así que ni siquiera tengo claro qué buscar para la solución. Este reemplazo funciona si el texto está fuera de la etiqueta. Pero si se introducen etiquetas de lista, el reemplazo no funciona.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

su principal problema es que no puede colocar una ul en la etiqueta ap, use div en su lugar. también simplemente configura el html a lo que quieras. vea abajo

 document.getElementById("demo").innerHTML = "<ul><li>Visit Microsoft!</li></ul>", "W3Schools";
 <h1>JavaScript Strings</h1> <h2>The replace() Method</h2> <p>replace() searches a string for a value, and returns a new string with the specified value(s) replaced:</p> <div id="demo"> <ul> <li>Visit Microsoft!</li> </ul> <ul> <li>The following required data are either missing, have errors, or are not being properly saved. Ensure the data are correct and then press 'Save' on the indicated tab. <ul> <li><a id='dataMissingHide95'>Items missing from the Sources of Funds tab (EXPAND)</a> <a id='dataMissingShow95' style='display:none;'>Items missing from the Sources of funds tab (COLLAPSE)</a> <ul id='itemsMissingShow95' style='display:none;'> <li><a id='dataMissingHide92'>Transaction information (EXPAND)</a> <a id='dataMissingShow92' style='display:none;'>Transaction information (COLLAPSE)</a> <ul id='itemsMissingShow92' style='display:none;'> <li>Investment experience (For any investment type checked, number of years must be selected.)</li> </ul> </li> </ul> </li> <li><a id='dataMissingHide91'>Items missing from the Transaction Disclosures tab (EXPAND)</a> <a id='dataMissingShow91' style='display:none;'>Items missing from the Transaction Disclosures tab (COLLAPSE)</a> <ul id='itemsMissingShow91' style='display:none;'> <li> Please answer the questions below on the Transaction Disclosures page and save the Transaction Disclosures page. <ul> <li>Explain in detail why this transaction is in the best interest of your client</li> </ul> </li> </ul> </li> </ul> </li> </ul> </div>

about 4 years ago · Juan Pablo Isaza Relatório

0

Puede navegar a través de su árbol si "demo" es un div como:

 <script> document.getElementById("demo").getElementsByTagName("ul")[0].getElementsByTagName("li")[0].innerHTML = "W3Schools"; </script>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda