After selecting a radio button with the ID "yourgoal", a div is displayed on my page. I want the page to scroll to that div only the first time a button in "yourgoal" is clicked. Below is the code I am currently using. However, I do not want the page to scroll to the div after the initial click.
$('input:radio[name="yourgoal"]').change(function() {
if ($('#calculations1').css('display') == 'none') {
$('html, body').animate({
scrollTop: $("#scrollto").offset().top
}, 1500);
}
The issue I'm facing is that it disrupts the other functions within the .change() method. I don't want to include all the functions inside the if statement and then duplicate them in an else {} block as it seems like too much repetitive code (which also causes issues). Is there a way to have a simple if statement that doesn't interfere with the rest of the actions in the .change function?
I might be overcomplicating this – perhaps there's a simpler solution?
Thank you in advance!