From f25eedf32a7555f71a246c6f491292ce876c4133 Mon Sep 17 00:00:00 2001 From: John Resig Date: Wed, 9 Dec 2009 21:28:33 -0800 Subject: [PATCH 1/1] Restrict the attr quick setters to only methods that specifically ask for the functionality. Fixes #5612. --- src/attributes.js | 17 ++++++++++++++++- src/event.js | 4 ++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/attributes.js b/src/attributes.js index 8080af8..fb5b16b 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -200,12 +200,27 @@ jQuery.each({ }); jQuery.extend({ + attrFn: { + val: true, + addClass: true, + css: true, + html: true, + text: true, + append: true, + prepend: true, + data: true, + width: true, + height: true, + offset: true + }, + attr: function( elem, name, value ) { // don't set attributes on text and comment nodes if (!elem || elem.nodeType == 3 || elem.nodeType == 8) { return undefined; } - if ( name in jQuery.fn && name !== "attr" ) { + + if ( name in jQuery.attrFn ) { return jQuery(elem)[name](value); } diff --git a/src/event.js b/src/event.js index f766896..a32f033 100644 --- a/src/event.js +++ b/src/event.js @@ -885,6 +885,10 @@ jQuery.each( ("blur focus load resize scroll unload click dblclick " + jQuery.fn[ name ] = function( fn ) { return fn ? this.bind( name, fn ) : this.trigger( name ); }; + + if ( jQuery.fnAttr ) { + jQuery.fnAttr[ name ] = true; + } }); // Prevent memory leaks in IE -- 1.7.10.4