Editor / DOM Helper / initSelect
Function: initSelect()
ts
function initSelect(
selector,
options,
params?): void;Initializes a <select> element with the given options.
- The function clears the existing options and populates the
<select>with new ones. - Supports an optional empty value.
- Allows pre-selecting an option based on the
paramsobject.
Parameters
| Parameter | Type | Description |
|---|---|---|
|
| The selector for the |
|
| An array of objects representing the options, with |
|
| Optional parameters for customization. |
Returns
void
Example
ts
initSelect('$select-id', [{ value: '1', text: 'Option 1' }, { value: '2', text: 'Option 2' }]);
initSelect('$select-id', [{ value: '1', text: 'Option 1' }], { emptyValue: 'Select an option', selected: '1' });