Skip to content

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 params object.

Parameters

ParameterTypeDescription

selector

string

The selector for the <select> element.

options

Record<string, string>[]

An array of objects representing the options, with value and text properties.

params?

InitSelectParams

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' });

Version v1.33.1 - Built on 2026-03-28