Selecciono un texto en la página html (abierta en firefox) usando el mouse, y usando las funciones de JavaScript, creo/obtengo el objeto de rango correspondiente al texto seleccionado.¿Cómo puedo resaltar el texto del objeto Rango DOM?
userSelection =window.getSelection();
var rangeObject = getRangeObject(userSelection);
ahora quiero resaltar todo el texto que depende del rangeobject.I estoy haciendo de esta manera,
var span = document.createElement("span");
rangeObject.surroundContents(span);
span.style.backgroundColor = "yellow";
Bueno, esto funciona bien, sólo cuando el rangeobject (punto inicial y punto final) se encuentra en la misma textNode, entonces se pone de relieve la text.Ex correspondiente
<p>In this case,the text selected will be highlighted properly,
because the selected text lies under a single textnode</p>
Pero si el rangeobject cubre más de un textNode, properlay entonces no está trabajando, él se destacan sólo los textos que estar en la primera textNode, Ex
<p><h3>In this case</h3>, only the text inside the header(h3)
will be highlighted, not any text outside the header</p>
alguna idea de cómo puedo hacer, todos los textos que depende rangeobject, destacó, independientemente de si se encuentra en rango de un solo nodo o varios nodos? Gracias ....
Posible duplicado: http://stackoverflow.com/questions/1622629/javascript-highlight-selected-range-button –