'jquery' tag

jQuery Input Text Replacement

7

Thought I’d save this handy dandy function for later.
Makes the text in an input disappear when you click on the input.

// the function:
function textReplacement(input){
 var originalvalue = input.val();
 input.focus( function(){
  if( $.trim(input.val()) == originalvalue ){ input.val(''); }
 });
 input.blur( function(){
  if( $.trim(input.val()) == '' ){ input.val(originalvalue); }
 });
}
// how to use:
textReplacement($('#inputname'));

Example:

jQuery Random Colour Generator

2

I can’t remember the inspiration for this crazy thing, but I’m sure somewhere out there someone is looking for a random colour generator that is done in jQuery.

So if you’re feeling in the mood to have a randomly changing colour … this is the script for you! Essentially it’s just generating a random number between 0 and 255 for red, green, and blue. It then uses CSS to change the colour property of an element (that’s easily customizable by you).

So check out the demo.