It works just fine if you switch the focus with the blur and use attr
() correctly :)

attr("prop") = retrieve property
attr("prop", "value") = set property

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

});

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

});


On Apr 18, 9:37 am, Brian Cummiskey <br...@hondaswap.com> wrote:
> 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