javascript - Select text of li elements through JQuery -


how can select text list elements through jquery. want same functionality of .select() in javascript, applicable editable text areas/input boxes, can guide me ,for same functionality list elements

i want list text selected on .click().

try this: http://jsfiddle.net/bigneo/w0y5yrcr/1/

html

<ul id="ulmonth">     <li>jan</li>     <li>feb</li>     <li>mar</li>     <li>apr</li>     <li>may</li>     <li>jun</li>     <li>jul</li>     <li>aug</li>     <li>sep</li>     <li>oct</li>     <li>nov</li>     <li>dec</li>     </ul> 

js

$.fn.oneclickselect = function(){     return $(this).on('click',function(){     var range, selection;     if (window.getselection) {             selection = window.getselection();                     range = document.createrange();             range.selectnode(this);             selection.removeallranges();             selection.addrange(range);      }       else if (document.body.createtextrange) {             range = document.body.createtextrange();             range.movetoelementtext(this);             range.select();      }     }); };  // apply these elements $('li, #all-select').oneclickselect(); 

i think found answer in post: https://codereview.stackexchange.com/questions/38089/select-text-with-just-one-click


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -