I'm trying to convert a simple normal inline JS to jQuery and am not having any luck:

<input type="text" name="q" id="q" value="Search" onfocus="if (this.value == this.defaultValue) this.value = '';" onblur="if (this.value == '') this.value=this.defaultValue;" />


I can't seem to find the right keyword for defaultValue in jQuery.

my code that doesn't work:

<input type="text" name="q" id="q" value="Search" />

$("#q").blur(function () {
        if ($(this).attr("value") == $(this).attr("defaultValue")) {
                $(this).attr("value") = '';
        }
});


$("#q").focus(function () {
        if ($(this).attr("value") == '') {
                $(this).attr("value") = $(this).attr("defaultValue");
        }
});



any suggestions?


Thanks!

Reply via email to