-1

I've got a script that scrolls the page to the top when a form in an iframe has submitted and new content loads into the iframe.

document.querySelector("iframe").addEventListener("load", 
function() {
    window.scrollTo({
top: 0,
left: 0,
behavior: 'smooth'
});
});

Instead of scrolling to the top I need the page to scroll to a particular element with a specific ID. How would that code need to change?

1
  • Thank you @SyndRain. But I'm having problems combining this with the code I've got. Commented May 3, 2024 at 6:35

1 Answer 1

0
document.getElementById("here is your element ID").scrollIntoView();
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. Are you able to tell me how to integrate this with the code I've already got?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.