javascript - Get all IDs of selected/highlighted DIVs -


I am going completely in the wrong direction, which I am trying to do, so I want to ask for help Was there.

Background / Overview

To display the text of the text and select one or more words from the paragraph and save their highlighted text The user needs to allow a database for, just for their profile, the cap of the text will eventually be selected (1) stored in the highlight and (2) on the second set of the second text highlighted from the second paragraph (original form From, i I'm typing in a reference source reference from source)

Whatever I have tried ...

I have a In the DIV (and a unique ID), we tried to keep each word of the paragraph float to the left, so that the display looks okay.

  & lt; Style & gt; Div {float: left} & lt; / Style & gt;   

And ... using an example:

  & lt; Div id = "GEN_1_1" & gt; & Lt; Div id = "GEN_1_1_1" & gt; In & lt; / Div & gt; & Lt; Div id = "GEN_1_1_2" & gt; & Lt; / Div & gt; & Lt; Div id = "GEN_1_1_3" & gt; Start & lt; / Div & gt; & Lt; Div id = "GEN_1_1_4" & gt; God & lt; / Div & gt; & Lt; Div id = "GEN_1_1_5" & gt; Created & lt; / Div & gt; & Lt; div id = "GEN_1_1_6" & gt; & Lt; / Div & gt; & Lt; div id = "GEN_1_1_7" & gt; Heaven & lt; / Div & gt; & Lt; div id = "GEN_1_1_8" & gt; And & lt; / Div & gt; & Lt; div id = "GEN_1_1_9" & gt; & Lt; / Div & gt; & Lt; div id = "GEN_1_1_10" & gt; Earth & lt; / Div & gt; & Lt; / Div & gt;   

It looks like: In the beginning God created heaven and earth. (less bold)

So far, I have highlighted the

  window .getSelection ()   

function Used to determine / capture the words.

Then I tried to use it:

  if (window.getSelection) {select_len = window.get selection} ToString () Length; If (window.getSelection (). ToString (). Length & gt; 0) {div_id = window.get Selection (). GetRangeAt (0) .commonAncestorContainer.parentNode.id; }   

To get the ID for each of the selected DIVs, but I only received one DIV ID.

Support request :

Whether there are methods to get the ID for each DIV and it is in an array So that I can create a SQL query to put it into the database (query is easy)? Selected words can be limited to thousands, if not, there are thousands of words, then I need to make sure the solution will work with a ton of words.

update:

I Modified by see that it works for you now.

  $ (document) .ready (function () {$ (document) .on ('mouseup keyup', '.checked', function () {Console.log (window.getSelection );; (Window.getSelection (). ToString (). Length & gt; 0) {var count = window.getSelection (); var arr = []; $ ('.check span') .ech (function ) {Var span = $ (this) [0]; var isT = window.getSelection (). ContainsNode (span, true); if (isT) {arr.push ($ (this) .attr ('id')) ;}}); Console.log (arr, count.toString ()); alerts; alerts (count.toString ());}});};   

I've made a bella for the solution to see it here:

In addition to this, I used to select div for text selection instead of Span I hope there will be no problem for you. So the code works as you wish, this parent will return the period's ID in which text is selected. You can save this ID in the array or according to your needs.

  $ (document) .ready (function () {$ (document) .on ('mouseup', 'check', function () {if (window.getSelection) {var i = getSelectionParentElement (); console.log (i); Warning ('parent selected:' + i.id);}});}); Function getSelectionParentElement () {var parent = null, selection; If (window.getSelection) {selection = window.getSelection (); If (selection.rangeCount) {origin = selection.getRangeAt (0) .commonAncestorContainer; If (parent.nodeType! = 1) {parent = parent.parentNode; }}} And if ((selection = document. Apple) and amp; amp; amp; amp; selection.Type! = "Control") {parent = selection.createRange () ParentElement (); } Return parents; }    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -