Autofocus on button click

I have a mobile layout where there is a signup button on top. On click of this button, the user is scrolled to an email form. I’d the email for to focus once the user is scrolled to the form. Any suggestions on how to achieve this?

Here is my public share link: [][1]

Hi Matthew, Welcome to the forum :webflow_heart:

You can add this to your custom code section:

$('.SignUpMobile').click(function () {
1 Like

Thanks @avivtech ! That seems to have worked.

can you offer explaination on the code. I’m trying somthing similar but the hash # location isn’t autofocusing? Is it based on the ID field?


Hi @miekwave,
Yea, the # is the HTML ID sign.

1 Like

Thanks @avivtech — Works great when the input field is on the same page as the link.

But what if the link is on a different page?

We’d have to add window.location.href to the script… But how?

Hi Dean,

This could be solved with a regular link to the page you want, and check the autofocus on the input field.

Cheers — That is definitely one way to do it. Just load the autofocus on the target page, and some conditions for when it will show (for example, the source page of the link)