Skip to content

Instantly share code, notes, and snippets.

@simonjodet
Created June 10, 2014 15:04
Show Gist options
  • Save simonjodet/8cbedc4929f08ecaa03e to your computer and use it in GitHub Desktop.
Save simonjodet/8cbedc4929f08ecaa03e to your computer and use it in GitHub Desktop.
Angular directive to select the content of a textarea when it's focused
'use strict';
angular.module('myApp').directive(
'ngSelectOnFocus',
function() {
var factory = {
restrict: 'A',
link: function postLink(scope, element) {
$(element).focus(function(event) {
event.target.select();
$(event.target).one('mouseup', function(e) {
e.preventDefault();
});
});
}
};
return factory;
}
);
<textarea ng-select-on-focus></textarea>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment