-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
prev()
function fails when non-element nodes are present
#30117
Conversation
prev()
function fails when non-element nodes are present
This probably fixes a bug in scrollspy so I moved this back to the v5 board. @XhmikosR, could you have a look at this? The test basically illustrates what the problem was. |
@MartijnCuppens is there any issue about this or failing snippets? Trying to understand why we need to make this change. |
Took a while to figure out where/how this was used, but i found what was going wrong, see |
It seems to be broken after the last merge, gonna check what happend there |
Lol, that was a lie, I just didn't scroll to the bottom to test this. Anyway, I finally get why @XhmikosR, can you recheck? |
It seems to work now, but maybe we should keep |
Why? previousSibling also targets comments and text elements which we do not need? (Also not sure what happens when we apply |
I meant just keep the variable and return |
But it's probably moot and the minifier might already drop this. I'll double check later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @MartijnCuppens 👍
The `prev()` function doesn't take nodes other than elements into account. Also we could simplify things a lot using the `previousElementSibling` property. This property isn't fully supported in IE, it only works for elements, but since the `element` variable is an element, we can safely use it here. I've also added an additional test. I don't think we had this issue in v4, since we relied on jQuery back then. Ref. https://developer.mozilla.org/en-US/docs/Web/API/NonDocumentTypeChildNode/nextElementSibling
The
prev()
function doesn't take nodes other than elements into account. Also we could simplify things a lot using thepreviousElementSibling
property. This property isn't fully supported in IE, it only works for elements, but since theelement
variable is an element, we can safely use it here.I've also added an additional test.
I don't think we had this issue in v4, since we relied on jQuery back then.
Ref. https://developer.mozilla.org/en-US/docs/Web/API/NonDocumentTypeChildNode/nextElementSibling