0

Right now on focus the input field simply hides the clear search button. What do I need to add on the focus event to highlight the value in the input field so when a user clicks on the input field the text already in there from the previous search is selected?

$('input.query').on('focus',function(){
    $("#searchx").hide();
});
$('input.query').on('blur',function(){
    $("#searchx").show();
});
Joe
  • 15,205
  • 8
  • 49
  • 56
oceanic815
  • 483
  • 2
  • 9
  • 20

2 Answers2

0

Answer: add this to the focus event:

$(this).select();
oceanic815
  • 483
  • 2
  • 9
  • 20
0

If you are concerned about cross browser functionality this will work better,

$(document).ready(function() {
    $("input.query")
        .focus(function () { 
             $("#searchx").hide();
             $(this).select(); 
        }).mouseup(function (e) {e.preventDefault(); });
});
rAjA
  • 899
  • 8
  • 13