Skip to main content

getSelection()

Description

Gets an array with ID of the selected task

Usage

getSelection(): (string | number | null)[];

Returns

The method returns an array with ID of the selected task

Example

const { ToDo, Toolbar } = todo;

const list = new ToDo("#root", {
tasks: [
{ id: "1", text: "Task 1 #tag1" },
{ id: "1.1", text: "Task 1.1", parent: "1" },
{ id: "1.1.1", text: "Task 1.1.1", parent: "1.1" },
{ id: "1.2", text: "Task 1.2", parent: "1" },
]
});

const toolbar = new Toolbar("#toolbar", {
api: list.api,
});

list.selectTask({
id: "1.1",
});

// get ID of the selected task
console.log(list.getSelection()); // -> ["1.1"]

Related article: Task object/Id