jquery function val() is not equivalent to "$(this).value="??

Posted by user323941 on Stack Overflow See other posts from Stack Overflow or by user323941
Published on 2010-12-24T06:47:51Z Indexed on 2010/12/24 6:54 UTC
Read the original article Hit count: 150

Filed under:

When I try to set a text input to blank (when clicked) using (this).value="", this does not work. I have to use $(this).val('').

Why? What is the difference? what is the mechanism behind of val function in jQuery?

quote:

$(document).ready(function() {
        $('#user_name').focus(
      function(){$(this).val('');}

     );
  });
//error code: not working...
 $(document).ready(function() {
        $('#user_name').focus(
      function(){$(this)value='';}

     );
  });

© Stack Overflow or respective owner

Related posts about jQuery