I know that jQuery has .select();
method , the question is can I get the value of this selection ?!
Simply i need to get the value of Highlighted characters inside text or input box.
Without using any plugins.
I know that jQuery has .select();
method , the question is can I get the value of this selection ?!
Simply i need to get the value of Highlighted characters inside text or input box.
Without using any plugins.
HTML
<input type="text" name="textbox1" />
jquery
$(document).ready(function(){
$('input[type="text"]').select(function() {
alert(window.getSelection());
});
});
You can use .selectionStart and .selectionEnd. For example: http://jsfiddle.net/tonicboy/225B8/
<input type="text" name="foobar" id="foobar" /><button type="button">Show Value</button>
$("button").click(function() {
var selected = getSelect($("#foobar"));
alert('highlighted text: ' + selected);
});
function getSelect($el) {
var fullvalue = $el.val(),
el = $el.get(0);
return $el.val().substring(el.selectionStart, el.selectionEnd);
}