Sunday, 18 August 2013

Implement placeholders in either html or razor view using jquery very easily

Jquery has very simple plugin for showing placeholders in textfields and textareas when they are empty like this :

you can download its plugin form there :

To use it in your applications just use its library in header like this :

<script src="jquery.placeholder.js"></script>
and use these lines:
    $('input[placeholder], textarea[placeholder]').placeholder();

in header and you can use in html like this :
<input type="password" placeholder="password" name="password">

and if you want to use this in mvc razor views , then use it in this way :
 @Html.TextBoxFor(x => x.Email, new { placeholder = "Email" })

That is how placeholders can be implemented very easily in any technology using jquery.