javascript to get paragraph of selected text in web page
问题 After highlighting text, I would like to obtain the paragraph in which the selected text resides. var select = window._content.document.getSelection(); Any pointers please? 回答1: This is actually rather hard to do because you have to consider six cases: The selection is not within a paragraph (easy); The entire selection is within one paragraph (easy); The entire selection crosses one or more sibling paragraphs (harder); The selection starts or ends in an element not within a paragraph (harder