Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear a textbox onfocus?

Tags:

jquery

I've tried this but it doesn't work:

$(function() {
    $('input[type=text]').focus(function() {
      $(this).val() == '';
      });
 });
like image 690
sarmenhb Avatar asked Sep 10 '25 06:09

sarmenhb


1 Answers

To set the value, you have to pass the new value as a parameter. This is a funky thing with the .val() jQuery function.

$(this).val('')

take a look at the jQuery API and search for 'val'

like image 164
Jon Erickson Avatar answered Sep 12 '25 22:09

Jon Erickson