Jquery and search form problem -


i can't jquery code clear search form when user clicks in search field can tell me i'm doing wrong?

jquery

$('#text').focus(function () {     if ($(this).val() == $(this).attr("title")) {         $(this).val("");     } }).blur(function () {     if ($(this).val() == "") {         $(this).val($(this).attr("title"));     } });   $("#searchform").submit(function() {     $("#text").each(function() {         if($(this).val() == this.title) {     $(this).val("");     }     }); }); 

html5 code

<header id="header"> <div id="header-con">     <h1>         <a href="" title=""><img src="" alt="" /></a>     </h1>      <nav id="nav">         <ul>             <li>a href="" title=""></a></li>             <li>a href="" title=""></a></li>             <li>a href="" title=""></a></li>             <li>                 <form method="post" action="" id="searchform">                     <fieldset>                         <input type="text" name="search" size="38" value="search..." title="search..." id="text" />                         <input type="submit" name="submit" value="search" id="sbutton" />                     </fieldset>                 </form>                          </li>         </ul>     </nav> </div> </header> 

since you're using html5, why aren't using placeholder attribute?

<input type="text" name="search" size="38" placeholder="search..." id="text" /> 

...and done. no javascript.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -