Skip to main content
added 1 characters in body
Source Link
Anujith
  • 9.4k
  • 6
  • 36
  • 48

See this : http://jsfiddle.net/rT5vR/

var t = ''; if(window.getSelection) { t = window.getSelection(); } else if(document.getSelection) { t = document.getSelection(); } else if(document.selection) { t = document.selection.createRange().text; } return t; } $("#myElement").select(function(eventObject) { alert(getSelected().toString()); }); 

​Or

$('#myElement').select(function(e) { var start = e.target.selectionStart; var end = e.target.selectionEnd; alert($('#myElement').val().substring(start, end)); }); 

}); ​

The second one is perfect. Don't know how much cross-browser the first one is... ​

See this : http://jsfiddle.net/rT5vR/

var t = ''; if(window.getSelection) { t = window.getSelection(); } else if(document.getSelection) { t = document.getSelection(); } else if(document.selection) { t = document.selection.createRange().text; } return t; } $("#myElement").select(function(eventObject) { alert(getSelected().toString()); }); 

​Or

$('#myElement').select(function(e) { var start = e.target.selectionStart; var end = e.target.selectionEnd; alert($('#myElement').val().substring(start, end)); 

}); ​

The second one is perfect. Don't know how much cross-browser the first one is... ​

See this : http://jsfiddle.net/rT5vR/

var t = ''; if(window.getSelection) { t = window.getSelection(); } else if(document.getSelection) { t = document.getSelection(); } else if(document.selection) { t = document.selection.createRange().text; } return t; } $("#myElement").select(function(eventObject) { alert(getSelected().toString()); }); 

​Or

$('#myElement').select(function(e) { var start = e.target.selectionStart; var end = e.target.selectionEnd; alert($('#myElement').val().substring(start, end)); }); 

The second one is perfect. Don't know how much cross-browser the first one is... ​

added 6 characters in body
Source Link
Anujith
  • 9.4k
  • 6
  • 36
  • 48

See this : http://jsfiddle.net/rT5vR/

var t = ''; if(window.getSelection) { t = window.getSelection(); } else if(document.getSelection) { t = document.getSelection(); } else if(document.selection) { t = document.selection.createRange().text; } return t; } $("#myElement").select(function(eventObject) { alert(getSelected().toString()); }); 

​Or

$('#myElement').select(function(e) { var start = e.target.selectionStart; var end = e.target.selectionEnd; alert($('#foo''#myElement').val().substring(start, end)); 

}); ​

The second one is perfect. Don't know how much cross-browser the first one is... ​

See this : http://jsfiddle.net/rT5vR/

var t = ''; if(window.getSelection) { t = window.getSelection(); } else if(document.getSelection) { t = document.getSelection(); } else if(document.selection) { t = document.selection.createRange().text; } return t; } $("#myElement").select(function(eventObject) { alert(getSelected().toString()); }); 

​Or

$('#myElement').select(function(e) { var start = e.target.selectionStart; var end = e.target.selectionEnd; alert($('#foo').val().substring(start, end)); 

}); ​

The second one is perfect. Don't know how much cross-browser the first one is... ​

See this : http://jsfiddle.net/rT5vR/

var t = ''; if(window.getSelection) { t = window.getSelection(); } else if(document.getSelection) { t = document.getSelection(); } else if(document.selection) { t = document.selection.createRange().text; } return t; } $("#myElement").select(function(eventObject) { alert(getSelected().toString()); }); 

​Or

$('#myElement').select(function(e) { var start = e.target.selectionStart; var end = e.target.selectionEnd; alert($('#myElement').val().substring(start, end)); 

}); ​

The second one is perfect. Don't know how much cross-browser the first one is... ​

added 214 characters in body
Source Link
Anujith
  • 9.4k
  • 6
  • 36
  • 48

See this : http://jsfiddle.net/rT5vR/

var t = ''; if(window.getSelection) { t = window.getSelection(); } else if(document.getSelection) { t = document.getSelection(); } else if(document.selection) { t = document.selection.createRange().text; } return t; } $("#myElement").select(function(eventObject) { alert(getSelected().toString()); }); 

​Or

$('#myElement').select(function(e) { var start = e.target.selectionStart; var end = e.target.selectionEnd; alert($('#foo').val().substring(start, end)); 

}); ​

The second one is perfect. Don't know how much cross-browser the first one is... ​

See this : http://jsfiddle.net/rT5vR/

var t = ''; if(window.getSelection) { t = window.getSelection(); } else if(document.getSelection) { t = document.getSelection(); } else if(document.selection) { t = document.selection.createRange().text; } return t; } $("#myElement").select(function(eventObject) { alert(getSelected().toString()); }); 

See this : http://jsfiddle.net/rT5vR/

var t = ''; if(window.getSelection) { t = window.getSelection(); } else if(document.getSelection) { t = document.getSelection(); } else if(document.selection) { t = document.selection.createRange().text; } return t; } $("#myElement").select(function(eventObject) { alert(getSelected().toString()); }); 

​Or

$('#myElement').select(function(e) { var start = e.target.selectionStart; var end = e.target.selectionEnd; alert($('#foo').val().substring(start, end)); 

}); ​

The second one is perfect. Don't know how much cross-browser the first one is... ​

Source Link
Anujith
  • 9.4k
  • 6
  • 36
  • 48
Loading