-
Notifications
You must be signed in to change notification settings - Fork 20.5k
Attributes: add SVG class manipulation #2268
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
Conversation
|
Interesting you got different results than me. I'm glad it's not a perf hit, though. |
|
@mzgol Oh, you got different results because I accidentally built on master and pushed master to dropbox. Please have a look again. |
|
Indeed, now it looks faster. No +1 but +2 then ;) |
|
@dmethvin Let's add this to the blog post! 😺 |
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.
Why do we need elem.getAttribute && bit?
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.
Even if we need it, maybe ternary would be better -
elem.getAttribute ? elem.getAttribute( "class" ) : ""then && & || magic
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.
We need the check because we have tests supporting some silent fails. The proposed alternative differs in logic. This way still returns an empty string in the case where getAttribute does not exist.
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.
We need the check because we have tests supporting some silent fails
Could you post the link?
This way still returns an empty string in the case where getAttribute does not exist.
Oh, same returned type, okay, cool
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.
I realised I said that wrong, but you got what I meant. getAttribute can return null and this ensures we return a string.
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.
I realised I said the wrong, but you got what I meant. getAttribute can return null and this ensures we return a string.
Aaam, if you said something wrong, i didn't notice :-), i meant it is good if some function always returns the same type.
I wondering about what tests we wouldn't pass though, if it would be just elem.getAttribute( "class" ) || ""?
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.
Here's the test that fails without the check https://github.com/jquery/jquery/blob/master/test/unit/attributes.js#L1073
- Note: support for SVG is limited in jQuery, but this is one area where the cost vs benefit ratio was acceptable. Fixes jquerygh-2199


+22 bytes. You may or may not be surprised that this is actually faster overall.
Fixes gh-2199