function getPosition () { if ($.browser.msie) { var textPosition = document.selection.createRange().duplicate(); } else($.browser.mozilla || $.browser.opera || $.browser.safari) { var textPosition = window.getSelection(); } } <div><textarea rows="3" cols="50" name="textarea1" id="textarea1" onChange="javascript:storeCursorPosition();" onClick="javascript:getPosition();" onKeyPress="javascript:getPosition();" onFocus="javascript:getPosition();"></textarea></div> <input type="Button" onclick="javascript:if(textPosition.text == null){alert('No position selected')}else{alert('position selected')};"> I have the above code, which is not working in Chrome, Safari etc. I'm getting the "No position selected" alert all the time, except for IE. In IE I get the "position" alert..
Any idea why it's not working except for IE??
textPositionhas no scope outside of the function.if (window.getSelection) { } else {}