tags:

views:

42

answers:

2

Im using this script for form titles:

$(document).ready(function(){
    $('.add-news').each( function () {
        $(this).val($(this).attr('defaultValue'));
        $(this).css({'color':'#686868' ,  'font-size':'11px', 'font-weight':'bold'});
    });
    $('.add-news').focus(function(){
        if ( $(this).val() == $(this).attr('defaultValue') ){
            $(this).val('');
            $(this).css({'color':'#686868' , 'font-size':'11px' ,'font-weight':'bold'});
        }
    });
    $('.add-news').blur(function(){
        if ($(this).val() == '' ){
            $(this).val($(this).attr('defaultValue'));
            $(this).css({'color':'#686868' ,  'font-size':'11px', 'font-weight':'bold'});
        }
    });

});

The example is here

This code working perfect for inputs, but in textarea, the above css doesnot work. How can I solve this? Thanks in advance

A: 

I think the right way is using .html() instead of .val() on TextArea elements.

Guilherme Oenning
i think your right, as text for inputs are stored within `value=""` you use `val()` but as textareas are stored as innerhtml you use `html()` :)
RobertPitt
I have tested before, Its not working.
phpExe
You have three calls changing css, which one doesn't work? Try using firefox error console to see if there is any error.
Guilherme Oenning
This is not correct, `.val()` should be used in both cases.
Nick Craver
Indeed. `html()` should definitely not be used. It should to map to `defaultValue`, but doesn't in IE due to a bug.
bobince
+3  A: 

After removing the obvious errors ('defaultue' instead of 'defaultValue', and missing commas in the objects of the css method) it works fine for me:

http://jsfiddle.net/TY2sf/

RoToRa
font size is not bold in text area. only works in inputs
phpExe
It is bold. At 11px (which is far to small anyway) the font you have may not look much different when bold.
RoToRa
I can see bold font in inputs. Its normal in textarea. and using:<textarea class="int add-news" defaultValue="Spot" cols="10" >Spot</textarea>
phpExe
In the example I posted it is most certainty bold. Which becomes obvious with a larger font size or using a csz
RoToRa
http://jsfiddle.net/BLrBd/
phpExe
Sorry, but it's bold. Have you tried a larger font or checked with a DOM/CSS inspector? Or I guess we need more information. What browser? What font is being used?
RoToRa
You are right. Thanks alot!
phpExe