Getting Started with EJ2 JavaScript Chips control
23 Nov 20262 minutes to read
This section explains the steps required to create a simple Essential® JS 2 Chips and demonstrate the basic usage of the Chips control in a JavaScript application.
Dependencies
The list of dependencies required to use the Chips component in your application is given below:
|-- @syncfusion/ej2-buttons
|-- @syncfusion/ej2-baseSetup for local environment
Refer to the following steps to set up your local environment.
Step 1: Create a root folder named my-app for your application.
Step 2: Create a my-app/resources folder to store local scripts and styles files.
Step 3: Open Visual Studio Code and create my-app/index.js and my-app/index.html files to initialize the Essential® JS 2 Chips control.
Control Initialization
The Essential® JS 2 JavaScript controls can be initialized by using below css styles and scripts
Add Syncfusion® Chips CSS Styles and Scripts
Include the following CSS and JavaScript files from CDN in the <head> section of the index.html file. The ej2-base scripts are required dependency packages for the Chips component.
Styles(CSS):
https://unpkg.com/@syncfusion/ej2-bootstrap5.3-theme/styles/chips/index.cssScripts (javascript):
https://cdn.syncfusion.com/ej2/35.1.37/ej2-base/dist/global/ej2-base.min.js
https://cdn.syncfusion.com/ej2/35.1.37/ej2-buttons/dist/global/ej2-buttons.min.jsAdding Chips component to the application
Add the <div> element and initialize the Essential® JS 2 Chips control in index.html using the following code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Essential JS 2</title>
<link href="https://unpkg.com/@syncfusion/ej2-bootstrap5.3-theme/styles/chips/index.css" rel="stylesheet" />
<!-- Essential JS 2 Base's global script (Dependency Script) -->
<script src="https://cdn.syncfusion.com/ej2/35.2.12/ej2-base/dist/global/ej2-base.min.js"
type="text/javascript"></script>
<!-- Essential JS 2 Button's global script -->
<script src="https://cdn.syncfusion.com/ej2/35.2.12/ej2-buttons/dist/global/ej2-buttons.min.js"
type="text/javascript"></script>
</head>
<body>
<div class="element">
<!-- Add the <div> element -->
<div id="chip">Janet Leverling</div>
</div>
<script>
// initialize and Render chip control
new ej.buttons.ChipList({ chips: ["Janet Leverling"] }, '#chip');
</script>
<style>
.element {
display: flex;
width: 400px;
margin: 100px auto;
border-radius: 3px;
justify-content: center;
}
</style>
</body>
</html>Step 4: Run the index.html in a web browser to render the Essential® JS 2 Chips control.