/ Published in: jQuery
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<script type="text/javascript"> $(document).ready(function(){ $('.inputfield').each(function(){ $(this).val(''); add_placeholder($(this)); }) $('.inputfield').focus(function(){ remove_placeholder($(this)); }).blur(function(){ add_placeholder($(this)); }).blur(); }); function add_placeholder(field) { var placeholder = field.attr('name'); if(field.val() == '') { field.val(placeholder); field.addClass('placeholder'); } } function remove_placeholder(field) { var placeholder = field.attr('name'); if(field.val() == placeholder) { field.val(''); field.removeClass('placeholder'); } } </script>