Change Textbox Background When it Receives Focus (asp.net)

Go To StackoverFlow.com

0

I want to reset the background image of a textbox when it receives focus. How can I do this?

2012-04-05 18:07
by Sufy Khan


0

If 'reset' means to clear out the background-image permanently, you'll need to manipulate the CSS via javascript events.

For example, if you use jQuery - you can do this:

$('input#some_id').focus(
  function(){ 
    $(this).css('background-image', 'none'); 
  }
);

Other JS libraries have similar functionality. If you aren't yet using a JS library, you may want to seriously consider it.

If you simply need to 'reset' temporarily until the focus leaves, you can use the ':focus' css pseudoclass like this:

input#some_id:focus
{
    background-image: none;
}
2012-04-05 18:15
by PinnyM


0

Something like this should work:

$("input").focus(function(){
    $("input").css("background-color","#FFFFCC"); //adjust for background-image
});
$("input").blur(function(){
    $("input").css("background-color","#ffffff"); //adjust for background-image
});
2012-04-05 19:04
by James Johnson
thanks for reply but I want image should get reset - Sufy Khan 2012-04-06 04:27
Ads