Permalink
Show file tree
Hide file tree
4 comments
on commit
sign in to comment.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Remove conditional that prevents attr from working on non-Element nod…
…es. Fixes #7451.
- Loading branch information
Showing
2 changed files
with
66 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a64dc04
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 think this change goes too far just to fix #7451. Now
attr()
even works on non DOM nodes. Is that intentional?If not pull request 92. test case which shows the problematic behavior.
Or does jQuery support plain javascript objects as collection elements (in several places there are checks for
nodeName
andnodeType
which indicate to me it doesn't)a64dc04
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.
It was doing it before already in 1.4.2 on everything except for text and comment nodes, unintentionally, through a call to jQuery.style. We can add back in a check to not run it on text/comment nodes but I am not sure if it makes any real sense to do that.
a64dc04
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 know this always unintentionally worked before 1.4.3. The check for text/comment nodes is still there,
attr()
doesn't set/get for those.I think
attr()
not supporting javascript objects would prevent people from adopting bad coding patterns, like usingattr()
to get/set attributes on objects. Betterobj.attrname
then$(obj).attr("attrname")
. If we don't care if it does/doesn't work with javascript objects it doesn't hurt to leave the DOM node check out.What I forgot to add to my comment above, and the test case, is that now
attr()
throws an exception when retrieving non existing attributes from a javascript object. updated test case showing the exception. Line in attribute.js where the exception happens.a64dc04
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.
Please check #7500 I updated the pull request accordingly.