Skip to content

Commit cdd5132

Browse files
committed
Fix #12026. Let props in $(html, props) be any jQuery.fn method.
Closes jquerygh-839.
1 parent 1e02761 commit cdd5132

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

src/attributes.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -281,17 +281,6 @@ jQuery.extend({
281281
}
282282
},
283283

284-
attrFn: {
285-
val: true,
286-
css: true,
287-
html: true,
288-
text: true,
289-
data: true,
290-
width: true,
291-
height: true,
292-
offset: true
293-
},
294-
295284
attr: function( elem, name, value, pass ) {
296285
var ret, hooks, notxml,
297286
nType = elem.nodeType;
@@ -301,7 +290,7 @@ jQuery.extend({
301290
return;
302291
}
303292

304-
if ( pass && name in jQuery.attrFn ) {
293+
if ( pass && jQuery.isFunction( jQuery.fn[ name ] ) ) {
305294
return jQuery( elem )[ name ]( value );
306295
}
307296

test/unit/core.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,24 @@ test("jQuery()", function() {
3535
"id": "test3"
3636
};
3737

38+
// The $(html, props) signature can stealth-call any $.fn method, check for a
39+
// few here but beware of modular builds where these methods may be excluded.
3840
if ( jQuery.fn.width ) {
3941
expected++;
4042
attrObj["width"] = 10;
4143
}
42-
4344
if ( jQuery.fn.offset ) {
4445
expected++;
4546
attrObj["offset"] = { "top": 1, "left": 1 };
4647
}
47-
48-
if ( jQuery.css ) {
48+
if ( jQuery.fn.css ) {
4949
expected += 2;
5050
attrObj["css"] = { "paddingLeft": 1, "paddingRight": 1 };
5151
}
52+
if ( jQuery.fn.attr ) {
53+
expected++;
54+
attrObj.attr = { "desired": "very" };
55+
}
5256

5357
expect( expected );
5458

@@ -107,11 +111,15 @@ test("jQuery()", function() {
107111
equal( elem[0].style.top, "1px", "jQuery() quick setter offset");
108112
}
109113

110-
if ( jQuery.css ) {
114+
if ( jQuery.fn.css ) {
111115
equal( elem[0].style.paddingLeft, "1px", "jQuery quick setter css");
112116
equal( elem[0].style.paddingRight, "1px", "jQuery quick setter css");
113117
}
114118

119+
if ( jQuery.fn.attr ) {
120+
equal( elem[0].getAttribute("desired"), "very", "jQuery quick setter attr");
121+
}
122+
115123
equal( elem[0].childNodes.length, 1, "jQuery quick setter text");
116124
equal( elem[0].firstChild.nodeValue, "test", "jQuery quick setter text");
117125
equal( elem[0].className, "test2", "jQuery() quick setter class");

0 commit comments

Comments
 (0)