Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

.attr('attribute', undefined) preserves the chain. Fixes #5571. #606

Closed
wants to merge 1 commit into from

1 participant

@gibson042
Collaborator

No description provided.

@gibson042 gibson042 closed this
@gibson042
Collaborator

Premature request. Withdrawn.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 2 deletions.
  1. +1 −1  src/attributes.js
  2. +7 −1 test/unit/attributes.js
View
2  src/attributes.js
@@ -12,7 +12,7 @@ var rclass = /[\n\t\r]/g,
jQuery.fn.extend({
attr: function( name, value ) {
- return jQuery.access( this, name, value, true, jQuery.attr );
+ return jQuery.access( this, name, arguments.length > 1 && value === undefined ? jQuery.noop : value, true, jQuery.attr );
},
removeAttr: function( name ) {
View
8 test/unit/attributes.js
@@ -158,7 +158,7 @@ test("attr(Hash)", function() {
});
test("attr(String, Object)", function() {
- expect(78);
+ expect(81);
var div = jQuery("div").attr("foo", "bar"),
fail = false;
@@ -353,6 +353,12 @@ test("attr(String, Object)", function() {
+ "</svg>").appendTo("body");
equal( $svg.attr("cx", 100).attr("cx"), "100", "Set attribute on svg element" );
$svg.remove();
+
+ // undefined value preserves chain (ticket #5571)
+ jQuery("#name").attr("maxlength", "5").removeAttr("nonexisting");
+ equal( typeof jQuery("#name").attr("maxlength", undefined), "object", ".attr('attribute', undefined) preserves chain (ticket #5571)" );
+ equal( jQuery("#name").attr("maxlength", undefined).attr("maxlength"), "5", ".attr('attribute', undefined) does not change value (ticket #5571)" );
+ equal( jQuery("#name").attr("nonexisting", undefined).attr("nonexisting"), undefined, ".attr('attribute', undefined) does not create attribute (ticket #5571)" );
});
test("attr(jquery_method)", function(){
Something went wrong with that request. Please try again.