Going a bit wild with that code, codeexploiter, perhaps. This should do the same thing:
Code:
<script type="text/javascript">
$(function(){
$(":text, textarea").focus(function(){
if($.trim(this.value) === $.trim(this.defaultValue)){
this.value = "";
}
}).blur(function(){
var value = $.trim(this.value);
if(value !== $.trim(this.defaultValue) && value === ""){
this.value = this.defaultValue;
}
});
});
</script>
Though I still prefer the:
Code:
jQuery(function($){
to the:
as it makes jQuery code by default into a sort of light noConflict mode, and can easily be made into full noConflict mode with:
Code:
jQuery.noConflict(function($){
All of which perform the same primary functionality (execute on document ready) of:
Code:
$(document).ready(function(){
Unfortunately though, I believe the defaultValue attribute has been deprecated. As far as I know, there is no easy valid workaround for that, though most browsers still support it.
Bookmarks