Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>-EDIT-</strong> What about this? it uses <code>getSelection()</code> binded to <code>mouseup</code></p> <pre><code>&lt;script type="text/javascript" src="jquery-1.6.3.min.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function(){ words = []; $("#myId").bind("mouseup",function(){ word = window.getSelection().toString(); if(word != ''){ if( confirm("Add *"+word+"* to array?") ){words.push(word);} } }); //just to see what we've got $('button').click(function(){alert(words);}); }); &lt;/script&gt; &lt;div id='myId'&gt; Some random text in here with many words huh &lt;/div&gt; &lt;button&gt;See content&lt;/button&gt; </code></pre> <hr> <p>I can't think of a way beside splitting, this is what I'd do, a small plugin that will split into <code>spans</code> and when clicked it will add its content to an <code>array</code> for further use:</p> <pre><code>&lt;script type="text/javascript" src="jquery-1.6.3.min.js"&gt;&lt;/script&gt; &lt;script&gt; //plugin, take it to another file (function( $ ){ $.fn.splitWords = function(ary) { this.html('&lt;span&gt;'+this.html().split(' ').join('&lt;/span&gt; &lt;span&gt;')+'&lt;/span&gt;'); this.children('span').click(function(){ $(this).css("background-color","#C0DEED"); ary.push($(this).html()); }); }; })( jQuery ); //plugin, take it to another file $(document).ready(function(){ var clicked_words = []; $('#myId').splitWords(clicked_words); //just to see what we've stored $('button').click(function(){alert(clicked_words);}); }); &lt;/script&gt; &lt;div id='myId'&gt; Some random text in here with many words huh &lt;/div&gt; &lt;button&gt;See content&lt;/button&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload