javascript - Cross-Browser way to select text -
I have a I want to select that text on click (like you use the mouse pointer and move the cursor) This can be a jQuery solution. In the comment, I was able to write the jQuery plugin with the help of @ADNow, select the text $ .browser has been removed, so it's jQuery & gt; Works for 1.9. p element, how can I choose the text inside javascript Will be - browser?
& lt; P & gt; Some text to choose from & lt; / P & gt;
$ .fn.sel = function () {var node = this [0]; If (document.body.createTextRange) {var category = document.body.createTextRange (); Range.moveToElementText (node); Range.select (); } And if (window.getSelection) {var select = window.getSelection (); If (select.setBaseAndExtent) {selection.setBaseAndExtent (node, 0, node, 1); } And if (document.createRange) {var range = document.createRange (); Range.selectNodeContents (node); Selection.removeAllRanges (); Selection.addRange (range); }}};
Comments
Post a Comment