I have a this text input
<input id="searchInput" type="text" value="Search Here" />
I want to remove the value of the input ie 'Search Here' as someone enters something ... How to do this in jQuery or in javascript ?
Simply use placeholder text
<input id="searchInput" type="text" placeholder="Search Here" />
http://www.w3.org/TR/html5/forms.html#the-placeholder-attribute
If the browser provides HTML5 capabilities you could simply use the placeholder
attribute.
However, if the user agent doesn't provide HTML5 capabilities you can use onfocus
and onblur
.
You can use Placeholder for your code.
<input id="searchInput" type="text" placeholder="Search Here" />
Here's a workind fiddle
Since you say jQuery, jquery-watermark is a good plugin.
It will add a watermark regardless of the browser capabilities.
It will use a placeholder if the browser supports it, and fallback to creating dom elements on browsers that don't
$('#searchInput').watermark('Search Here');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.