Skip to content

Instantly share code, notes, and snippets.

@netsi1964
Created June 12, 2012 08:32
Show Gist options
  • Save netsi1964/2916198 to your computer and use it in GitHub Desktop.
Save netsi1964/2916198 to your computer and use it in GitHub Desktop.
Netsi1964 HTML SNIPPETS
Netsi1964 HTML SNIPPETS
<!-- Simpel default/placeholder value for textarea, require jQuery -->
<textarea name="" id="" cols="30" rows="10" placeholder="test">test</textarea>
<script type="text/javascript">
$(function() {
var test = document.createElement('textarea');
if (!!!('placeholder' in test)) {
jQuery('textarea').focus(function() {
var $this = $(this);
if ($.trim($this.val())===$this.attr('placeholder')) {
$this.val('');
}
}).blur(function() {
var $this = $(this);
if ($.trim($this.val()).length===0) {
$this.val($this.attr('placeholder'));
}
});
};
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment