Tuesday, 8 November 2016

jQuery make input element select value when it gets focus.

I think this makes inputs more user friendly in that focus can be assigned and the user can start typing to replace the number.

// A behavioural change to all input elements.
// Make them select the text when they get focus.
$(document).ready(function() {
    $('body').on('focusin', 'input', function() {
        console.log('Input selected:', this.id, this.name);