How to use jQuery to change the background color of a textbox?

mike picture mike · Aug 3, 2009 · Viewed 67.1k times · Source

How to use jQuery to change the backgound color of a textbox?

Answer

Dykam picture Dykam · Aug 3, 2009

Better practice is to seperate UI from logic, in your case:

$("#textboxid").addClass("aClass");

If you really need it your way, then do the following:

$("#textboxid").css({"background-color": "color"});

Replace #textboxid with the desired selector, and color with the desired color.

Note the following does the same for one property:

$("#textboxid").css("background-color", "color");