{"id":124,"date":"2013-01-30T11:35:27","date_gmt":"2013-01-30T09:35:27","guid":{"rendered":"http:\/\/www.ygo.ro\/?p=124"},"modified":"2013-01-30T11:38:14","modified_gmt":"2013-01-30T09:38:14","slug":"clear-and-restore-default-text-in-input-with-jquery","status":"publish","type":"post","link":"https:\/\/ygo.ro\/?p=124","title":{"rendered":"Clear and restore default text in input with jQuery"},"content":{"rendered":"<p>Today I wanted to put some text in a input for user, so he know what values should type in. When you do that the problem is if user let the field blank you have to reload the text again. The most common is the username input where you want to have \"Username\" text.<br \/>\nAfter many iteration of the javascript code (going back to the old days when there was no fancy library) I refined my code to this:<br \/>\n<code><br \/>\nvar tempVal = \"\";<br \/>\n$(\".someclass\").focus(function(){tempVal = $(this).val();$(this).val(\"\");}).blur(function(){if($(this).val()==\"\") {$(this).val(tempVal);}});<br \/>\n<\/code><\/p>\n<p>That's a pretty neat piece of code \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I wanted to put some text in a input for user, so he know what values should type in. When you do that the problem is if user let the field blank you have to reload the text again. The most common is the username input where you want to have &#8220;Username&#8221; text. After [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46,47],"tags":[48,72],"_links":{"self":[{"href":"https:\/\/ygo.ro\/index.php?rest_route=\/wp\/v2\/posts\/124"}],"collection":[{"href":"https:\/\/ygo.ro\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ygo.ro\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ygo.ro\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ygo.ro\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=124"}],"version-history":[{"count":4,"href":"https:\/\/ygo.ro\/index.php?rest_route=\/wp\/v2\/posts\/124\/revisions"}],"predecessor-version":[{"id":128,"href":"https:\/\/ygo.ro\/index.php?rest_route=\/wp\/v2\/posts\/124\/revisions\/128"}],"wp:attachment":[{"href":"https:\/\/ygo.ro\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ygo.ro\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ygo.ro\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}