Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Stop writing the same damn code over and over again to handle swapping input
- text on focus/blur. Store the original using jQuery.data(), and have this
- be as agnostic as possible. ;P
- */
- var page = {
- inputs: {
- checkAndStore: function() {
- var val = $(this).val(),
- stored = $.data($(this)[0], "original_text");
- /* Store the original value on the first pass through */
- if(typeof stored === "undefined") {
- $.data($(this)[0], "original_text", val);
- stored = val;
- }
- if(val === stored) $(this).val("");
- },
- checkAndReset: function() {
- if($(this).val() === "")
- $(this).val($.data($(this)[0], "original_text"));
- }
- }
- };
- /* Super simple focus/blur text handling */
- $(".myElements").focus(page.inputs.checkAndStore).blur(page.inputs.checkAndReset);
Add Comment
Please, Sign In to add comment