@page "/" @using Microsoft.JSInterop @inject IJSRuntime JS @functions{ ElementReference TextAreaRef; int lineNumber = 0; string TextAreaText = "Keep clicking the button and watch the vertical scroll move down.\n"; void ScrollToEnd() { lineNumber++; TextAreaText += $"Line number {lineNumber}\n"; JS.InvokeVoidAsync("scrollToEnd", new object[] {TextAreaRef}); } } <p> Demostrates how to call a JavaScript function from C# that scrolls a textarea to the end. </p> <button class="btn btn-primary m-2" @onclick="ScrollToEnd">Add Line</button> <br/> <textarea @ref=TextAreaRef value="@TextAreaText" class="form-control" rows="5"></textarea>
namespace BlazorFiddleProject { using Microsoft.AspNetCore.Components.Builder; using Microsoft.Extensions.DependencyInjection; public class Startup { public void ConfigureServices(IServiceCollection services) { } public void Configure(IComponentsApplicationBuilder app) { app.AddComponent<App>("app"); } } }
<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <meta name="viewport" content="width=device-width"> <title>BlazorFiddleProject</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> <style> app { } </style> <script type="text/javascript"> function scrollToEnd(textarea) { textarea.scrollTop = textarea.scrollHeight; } </script> </head> <body> <app>Loading...</app> <script src="_framework/blazor.webassembly.js"></script> </body> </html>

Add component

BlazorFiddle was updated from Blazor 0.7 to .NET 6.0. Your old source code could not work. You need to upgrade to latest.