Text replacement technique
Is there a better way to do this? Basically I am inserting text into a form field, and clearing it if it gets focused, and putting the text back if nothing changes. Everything works, just want to know if it can be done more cleverly.
Thanks in advance!
- function textReplace(selector,text) {
- $(selector).val(text);
- $(selector).bind({
- focus: function() {
- if($(this).val() == text) { $(this).val(""); }
- },
- focusout: function() {
- if($(this).val() == "") { $(this).val(text); }
- }
- });
- }