views:

33

answers:

3

And how do you make the text disappear when you click into the field and reappear when you click out of it?

+1  A: 

do you just mean the color attribute for your first question? As for making the text disappear when you click into the field, do you mean an html input field?

If it is just a div, then setting an onmouseover and onmouseout event to hide the div (maybe use display:block and display:none) can accomplish that.

stevebot
Yea, the color attribute a.k.a. the color of the text. In the input tag where you have value="X" I want to change the color of X. And yes, an html input field.
Justin Meltzer
+1  A: 

The color css property is used to set the text color. You can use a name value, rgb value, or hex value.

Changing the visibility of elements in reaction to events will required some javascript knowledge. You can use jQuery, which is a javascript library, to accomplish this. By toggling behaviors, you could make an element disappear and then reappear.

If you're wanting something like having default text in the textbox until the user focuses on that, you'll need to handle the focus and blur events. This posting has a tutorial on this.

rchern
I tried using the color css property. I can't seem to change the text X within value="X" of the input tag though. How should I adapt my html code?
Justin Meltzer
@Justin, here's a live, working example: http://jsfiddle.net/H3Tr3/
rchern
+1  A: 

CSS:

input.placeholder {
    color:#ccc;
}

JavaScript:

(function() {
    var placeholders = document.getElementsByClassName('placeholder');
    for(var p = 0; p < placeholders.length; p++) {
       var placeholder = placeholders[p];
       placeholder.onfocus = function() {
          this.value = '';
          this.removeClass('placeholder');
       };
       placeholder.onblur = function() {
          if(this.value == '') {
             this.addClass('placeholder');
          }
       }
    }
})();
Jacob Relkin