javascript - Text select (ready to use clipboard operations) -
http://cdnjs.com/libraries/twitter-bootstrap/
in website when mouseover links given text selected(like mouse text select , not css styling).
i tried check what's changing in inspect element found none.
i tried find out if js or jquery has methods this. found .select() method of jquery usable on form elements , there no deselect() method in jquery definetely no that.
so whats under hood?
update:
i found solution tried in jsfiddle works perfect. written in js dom node manupulations , looks greek , latin me. not able write jquery version of algorithm.
html:
<p id="selectable">hello</p>
js:
function fnselect(objid) { fndeselect(); if (document.selection) { var range = document.body.createtextrange(); range.movetoelementtext(document.getelementbyid(objid)); range.select(); } else if (window.getselection) { var range = document.createrange(); range.selectnode(document.getelementbyid(objid)); window.getselection().addrange(range); } } function fndeselect() { if (document.selection) document.selection.empty(); else if (window.getselection) window.getselection().removeallranges(); } $(document).ready(function(){ $("p").on("mouseover",function(){ var id = $(this).attr("id"); fnselect(id); }); $("p").on("mouseout",function(){ fndeselect(); }); });
finding way more trouble should have been. here's can use:
window.getselection().selectallchildren(elementobject);
extended studies found here (mdn again)
if me, achieve effect:
function onmouseover(e) { window.getselection().selectallchildren(e.currenttarget); } function onmouseout(e) { window.getselection().removeallranges(e.currenttarget); } document.getelementbyid("top").addeventlistener("mouseenter", onmouseover, false); document.getelementbyid("top").addeventlistener("mouseleave", onmouseout, false);
Comments
Post a Comment