/ Published in: jQuery
URL: http://www.me.com
For an example, visit MobileMe. Inspired by the writeup at Smashing Magazine. However, I wanted to take this in a direction that was easier to implement. There is the issue of accessibility without the use of Labels, but I plan on addressing this at a later date.
Expand |
Embed | Plain Text
// BEGIN JQUERY jQuery.fn.simplehints = function() { return this.each(function() { var $this = $(this); if ($this.attr('value').length == 0) $this.attr('value', $this.attr('title')); if ($this.attr('value').length != 0 && $this.attr('value') != $this.attr('title')) $this.addClass("bold"); $(this).focus(function () { if ($this.attr('value') == $this.attr('title')) $(this).get(0).setSelectionRange(0,0); }).keypress(function() { if ($this.attr('value') == $this.attr('title') && $this.attr('type') != 'select-one') $this.attr('value', '').addClass("bold"); }).change(function() { if ($this.attr('value') != $this.attr('title')) $this.addClass("bold"); if ($this.attr('value') == $this.attr('title')) $this.removeClass("bold"); }).blur(function() { if ($this.attr('value') == '') $this.attr('value', $this.attr('title')).removeClass("bold"); }).parents('form').submit(function(e) { if ($this.attr('value') == $this.attr('title')) $this.attr('value', ''); }); }); }; $(document).ready(function(){ $(this).find('form .hint').simplehints(); }); // END JQUERY // BEGIN CSS .input, .select, .textarea { background: #fff; border: 1px solid #aaa; padding: 5px; margin-top: 8px; margin-bottom: 5px; width: 380px; font-size: 14px; font-weight: 700; color: #bbb; } input.bold, select.bold, textarea.bold { color: #000; } .checkbox, .radio{ margin: 10px 0 0 0; } .select{ width: 390px; } .textarea{ float: left; height: 200px; width: 385px; margin-top: 15px; overflow: auto; font-family: inherit; } // END CSS // BEGIN HTML <input type="text" name="email" class="input hint" title="Email Address" value="" /> // END HTML
Comments
Subscribe to comments
You need to login to post a comment.

you don't need to put it in jquery dom ready.
doh!