Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions knowledge-base/editor-get-selection.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
---
title: Get the content of the Editor selected by the user
description: How to get the content of the Editor selected by the user
description: Learn how to retrieve the selected text from the Telerik Editor using JavaScript to apply custom formatting dynamically.
type: how-to
page_title: Get the user selection in the Editor
slug: editor-kb-get-selection
position:
tags:
tags: editor, selected, text, highlighted
res_type: kb
---

Expand Down Expand Up @@ -53,23 +52,22 @@ If you want to use it on the .NET (Blazor) side, you need to:

@inject IJSRuntime js

<TelerikEditor Tools="@Tools" @bind-Value="@TheEditorContent" EditMode="@EditorEditMode.Iframe">
<TelerikEditor Tools="@Tools" @bind-Value="@TheEditorContent" EditMode="@EditorEditMode.Div">
<EditorCustomTools>
<EditorCustomTool Name="GetSelectedText">
<TelerikButton OnClick="@GetSelectedText">Get selected text</TelerikButton>
</EditorCustomTool>
</EditorCustomTools>
</TelerikEditor>


Selected text: @SelectedText

@code {
string TheEditorContent { get; set; } = "<h1>Lorem ipsum</h1><p>Dolor sit amet.</p>";
List<IEditorTool> Tools { get; set; }
public string SelectedText { get; set; }
private string TheEditorContent { get; set; } = "<h1>Lorem ipsum</h1><p>Dolor sit amet.</p>";
private List<IEditorTool> Tools { get; set; }
private string SelectedText { get; set; }

async Task GetSelectedText()
private async Task GetSelectedText()
{
SelectedText = await js.InvokeAsync<string>("getSelectedText");
}
Expand Down Expand Up @@ -120,15 +118,14 @@ If you want to use it on the .NET (Blazor) side, you need to:
</EditorCustomTools>
</TelerikEditor>


Selected text: @SelectedText

@code {
string TheEditorContent { get; set; } = "<h1>Lorem ipsum</h1><p>Dolor sit amet.</p>";
List<IEditorTool> Tools { get; set; }
public string SelectedText { get; set; }
private string TheEditorContent { get; set; } = "<h1>Lorem ipsum</h1><p>Dolor sit amet.</p>";
private List<IEditorTool> Tools { get; set; }
private string SelectedText { get; set; }

async Task GetSelectedText()
private async Task GetSelectedText()
{
SelectedText = await js.InvokeAsync<string>("getSelectedText");
}
Expand Down
Loading