K
K
Konstantin2020-09-03 18:13:34
Angular
Konstantin, 2020-09-03 18:13:34

How to scroll to a DOM element?

There is a block

<div id="section_GENERICPARAMETERS_GENERICPARAMETERS"></div>


By clicking on the link, I scroll to this block

public scrollTo(e, id: string): void {
        e.preventDefault();
        const targetElement = document.getElementById(id);
        targetElement.scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'nearest' });
    }


But it doesn't work. There are no errors. The element is definitely on the page (dialog box).
What could be the problem?

Could the reason be that the DOM element is being built dynamically?

Maybe get all the children @ViewChildren() itemElements: QueryList<any>;

then loop through them and compareitem.id == selectedItem.id

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question