deleting only a selected text in a text area txtArea.replaceSelection(""); this should be shorter and more effective.