aspnet-404592-common-concepts-client-side-functionality-change-element-style.md
This topic describes different ways to change element styles in DevExpress controls on the client side.
Most DevExpress controls have the client GetMainElement method that returns the root HTML element of the control. You can use this element to change the style of a simple control, such as ASPxButton or ASPxImage.
<dx:ASPxButton ID="btn" runat="server" Text="Some Text Here..." ClientInstanceName="button" />
<dx:ASPxImage ID="img" runat="server" ImageUrl="../myImg.jpg" ClientInstanceName="image" Width="100px"/>
var buttonElement = button.GetMainElement();
buttonElement.style.backgroundColor = "Black";
buttonElement.style.color = "Green";
var imageElement = image.GetMainElement();
imageElement.style.border = "thick solid #d12501";
Note
When an element has a background image, it overlaps the applied background color. Refer to the following article for details: How to correctly apply a custom background color to a specific visual element of the themed control or extension.
Call the GetInputElement method to get an editor’s HTML <input> element. Use this element to customize input style settings.
<dx:ASPxTextBox ID="tb" runat="server" ClientInstanceName="textBox" />
var tbInputElement = textBox.GetInputElement();
tbInputElement.style.color = "Gray";
tbInputElement.style.cursor = "not-allowed";
tbInputElement.readOnly = true;
You can apply a custom CSS class to every element that have the CssClass property, find this element by class name on the client, and modify the element’s style settings. To implement this technique, follow the steps below:
Apply a custom CSS class to an element.
On the client, call the getElementsByClassName method to get a collection of elements with the specified class name(s).
Use jQuery to change style settings for all elements that contain the specified CSS class.
$('.dpHeader').css({ 'background-Color': "Yellow" });