JavaScript/jQuery Button - Getting Started

NOTE
Before you start the tutorial, ensure DevExtreme is installed in your application.

This tutorial shows how to add a Button to a page, apply styling, and configure its core features. As a result, you will create the following UI component:

Refer to the following sections for information on each configuration step. The full code is available in the following GitHub repository: getting-started-with-button.

Create a Button

Add DevExtreme to your jQuery application and use the following code to create a Button:

index.js
index.html
  • $(function() {
  • $("#button").dxButton({
  • text: "Click me!"
  • });
  • });
  • <html>
  • <head>
  • <!-- ... -->
  • <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  •  
  • <link rel="stylesheet" href="https://cdn3.devexpress.com/jslib/21.2.15/css/dx.light.css">
  • <link rel="stylesheet" href="index.css">
  •  
  • <script type="text/javascript" src="https://cdn3.devexpress.com/jslib/21.2.15/js/dx.all.js"></script>
  • </head>
  • <body class="dx-viewport">
  • <div id="button"></div>
  • </body>
  • </html>

Handle the Click Event

To respond to user clicks, write an onClick handler. The example used in this tutorial displays a toast message:

index.js
  • $(function() {
  • $("#button").dxButton({
  • // ...
  • onClick: function() {
  • DevExpress.ui.notify("The button was clicked");
  • }
  • });
  • });

Stylize the Button

You can use the type property to apply predefined color schemes to Buttons. You can also use the stylingMode property to customize the fill and borders. Refer to the Predefined Types demo for more information about these properties.

index.js
  • $(function() {
  • $("#button").dxButton({
  • // ...
  • type: "success",
  • stylingMode: "outlined"
  • });
  • });

Add an Icon

Use the icon property to add a glyph to the button. You can load a custom icon or display one of the ready-to-use images from different image sources. The sample below shows how to use a glyph from the DevExtreme library:

index.js
  • $(function() {
  • $("#button").dxButton({
  • // ...
  • icon: "comment"
  • });
  • });

For more information on this UI component, refer to the following resources: