my jquery hint only works if in an textbox and not a a textarea. How to I make it work for both.
$(document).ready(function() {
//Shows the title in the text box, and removes it when modifying it
$('input[title]').each(function(i) {
if(!$(this).val()) {
$(this).val($(this).attr('title')).addClass('hint');
}
only works on:
<input type="text" name="name" title="Full Name" >
but not on:
<textarea title="Enter Message Here"name="message" rows=8 cols=30 </textarea>
Your current selector,
$('input[title]')says to select inputs with a title attribute set. It doesn’t say anything about textareas.You need to do this:
Or, arguably better:
The first says to select all input elements with a title attribute and all textarea elements with a title attribute. The second uses jQuery’s
:inputselector which automatically grabs all input, textarea, select and button elements (i.e., all form elements), but in this case restricted to those with a title attribute.Working demo: http://jsfiddle.net/qMLRK/
NOTE: you should allow for spaces in the fields because
<textarea> </textarea>is not empty: