Open scripting opened 5 months ago
I believe this is because the anchor is written like this: <a class="dropdown-toggle" href="#"
Since hashtags are also used as anchors, it jumps so the top of the viewport goes to that anchor. There are a couple of ways to handle it. One would be to use a button instead of an anchor tag, which would probably be more in line with JavaScript best practices.
The quicker solution would be to write your anchor tag like this: <a class="dropdown-toggle" href="javascript:void(0);"
This should prevent it from jumping. Let me know if it doesn't, and I can research further.
Thanks for the idea -- I did it the easy way, replacing the # with javascript:void(0); but no luck. It still scrolls to the top when you click it.
When you say use a button, not sure what means. Changing the <a>
to a <button>
?
I checked with ChatGPT and it offered similar advice. Oy. (See the second suggestion.)
I'm going to try the first one, see if it works.
I tried switching it to a button too (pretty straightforward) and it still scrolled to the top.
Theory: Some other code is catching the click and scrolling to the top. (Haven't had a chance yet to fully explore this.)
Right now this is not a super high priority, so I'm going to go look at some other problems and see if I can figure them out.
Hm. I'm surprised that's not working for you. I tried it locally, and it seemed to work 🤔
One thing I've done in the past also is to add preventDefault to the click event script.
For example:
$('a.someclass').click(function(e) {
e.preventDefault();
});
Oh ha. I see that ChatGPT beat me to it 😆
We'll figure this one out, esp since you had it working there. I was probably making some mistake.
BTW, this bug isn't holding us back. The one I really want to understand is the underlining that isn't underlining (in the previous issue).
I did a video demo of this problem. Has nothing to do with any particular site.
https://www.youtube.com/shorts/iUGJJyANBR8
This is relatively new behavior. Something I did must have broken it..
Any ideas welcome. ;-)