내가 jQuery를에 순수 JS 텍스트 하이라이트 스크립트를 변환하고 있어요,하지만 난 insertNode
에 jQuery를 동등한이 무엇인지 알아 내려고 노력 해요 :jQuery는 insertNode에 해당합니까?
var selection = window.getSelection().getRangeAt(0);
var selectedText = selection.extractContents();
var span = document.createElement("span");
span.style.backgroundColor = "yellow";
span.appendChild(selectedText);
selection.insertNode(span);
가 나는 다음을 사용할 수 있습니다 생각 결과
var span = $("<span class='highlight'>" + selectedText + "</span>");
selection.insertNode(span);
:
NOT_FOUND_ERR: DOM Exception 8: An attempt was made to reference a Node in a context where it does not exist.
, 왜 당신이 그것을 변환하는 그래서이 시도? –
내 페이지의 나머지 부분은 jQuery에 있으므로 제복이 필요합니다. – Charlie
__jQuery는 JavaScript__입니다. – Mathletics