How can I leverage the same functionality of .select() but for elements other textboxes such as list elements?
Edit: To clarify, I'm not looking to retrieve the selected text, I want to make it such that a key combo will trigger the selection of a list elem开发者_StackOverflow中文版ents for example.
Well while w8ting for a good answer i found this plugin that seems to work perfectly
http://mark.koli.ch/2009/09/use-javascript-and-jquery-to-get-user-selected-text.html
if you want to do the selecting part there is another plugin here
http://www.ryantetek.com/2010/02/selecting-text-inside-html-elements-with-jquery/
It's not a direct approach, but you can listen for mouseup
, then check to see if there's a selection. It's not exactly what you asked for, but it might get you close.
Here's an example on jsFiddle
精彩评论