Tengo HTML donde algunos párrafos contienen elementos <mark>
. Esto hace que se resalte el texto dentro del elemento <mark>
. Esencialmente, quiero eliminar el resaltado eliminando el elemento <mark>
pero manteniendo el contenido del texto.
¿Cuál es la mejor manera de hacer esto?
Aquí hay un párrafo de ejemplo:
Quiero eliminar el texto resaltado. El HTML contiene <span>
y otros elementos y algunos elementos <mark>
que no quiero eliminar. Los que quiero eliminar tienen una clase de .show-mark. Sé cómo encontrar solo los elementos <mark>
que quiero eliminar, pero no sé cómo eliminarlos.
Aquí está el HTML para el párrafo de ejemplo:
<p id="p85" class="cmiTranPara note-style-bookmark note-style-bookmark-start note-style-bookmark-end"> <i class="playmark play icon"></i> <i class="timing large circular red clock icon"></i> <span class="pnum has-annotation" data-aid="1574791210024">(p85) </span> Miracle-mindedness is still a stage of perception just short of <mark class="show-mark">master</mark>y. For <mark class="show-mark">master</mark>y comes when you know that you are literally and deliberately creating. And there is nothing miraculous about it. You will decree a thing and it shall be so! </p>
Gracias por tu ayuda.
Prueba algo como esto
targets = document.querySelectorAll("mark"); for (let target of targets) { target.outerHTML=target.innerHTML; }
y ver si funciona.