Created
March 10, 2011 14:57
-
-
Save chriscoyier/864210 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
var $el; | |
$("input[placeholder]").each(function() { | |
$el = $(this); | |
$el | |
.css("color", "#ccc") | |
.val($el.attr("placeholder")) | |
.data("orig-text", $el.val()) | |
// knows data here | |
$el | |
.focus(function() { | |
$el = $(this); | |
// undefined data here | |
if ($el.val() == $el.data("orig-text")) { | |
alert("it's the same"); | |
$el.val(""); | |
$el.css("color", "black"); | |
} | |
}) | |
.blur(function() { | |
$el = $(this); | |
if ($el.val() == "") { | |
$el.val($el.data("orig-text")); | |
$el.css("color", "#ccc"); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can't test it since IE9 doesn't seem to have a problem, but I seem to remember the problem is older IE versions don't like dashes in the data name.