-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkcplaceholder.js
21 lines (17 loc) · 910 Bytes
/
kcplaceholder.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$(function(){
// Remove placeholder when the element is brought into focus
$('[placeholder]').focus(function() {
var element = $(this), value = element.val(), placeholder = element.attr('placeholder');
if (value == placeholder) {element.val('');}
// Put the placeholder text back into the element if it's empty
}).blur(function() {
var element = $(this), value = element.val(), placeholder = element.attr('placeholder');
if (value == '' || value == placeholder) {element.val(placeholder);}
// Before the form is submitted, we need to remove all our placeholder text so it does not get submitted with the form
}).blur().parents('form').submit(function() {
var element = $(this), value = element.val(), placeholder = element.attr('placeholder');
element.find('[placeholder]').each(function() {
if (value == placeholder) {element.val('');}
})
});
});