jquery.getAttrs: Replace deprecated nodeName/nodeValue with Attr.name/value
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 4 Nov 2014 00:00:20 +0000 (00:00 +0000)
committerTimo Tijhof <krinklemail@gmail.com>
Tue, 4 Nov 2014 00:19:12 +0000 (00:19 +0000)
Chrome emits the following warning:
> 'Attr.nodeValue' is deprecated. Please use 'value' instead.

Attr.nodeName and nodeValue are not part of the DOM standard.
https://dom.spec.whatwg.org/#interface-attr

Attr.name and Attr.value are supported since at least IE8.
Confirmed the unit tests passing in IE8.

Simplify and improve the unit tests for jquery.getAttrs.

Change-Id: Ic086ece34b214dede26371cbc03ede0f2af37c54

resources/src/jquery/jquery.getAttrs.js
tests/qunit/suites/resources/jquery/jquery.getAttrs.test.js

index 5ad7648..5d6a1d4 100644 (file)
@@ -17,7 +17,7 @@ jQuery.fn.getAttrs = function () {
                len = map.length;
 
        for ( i = 0; i < len; i++ ) {
-               attrs[ map[i].nodeName ] = map[i].nodeValue;
+               attrs[ map[i].name ] = map[i].value;
        }
 
        return attrs;
index 0b7e87e..ca3f418 100644 (file)
@@ -1,13 +1,14 @@
 ( function ( $ ) {
        QUnit.module( 'jquery.getAttrs', QUnit.newMwEnvironment() );
 
-       QUnit.test( 'Check', 1, function ( assert ) {
+       QUnit.test( 'getAttrs()', 1, function ( assert ) {
                var attrs = {
                                foo: 'bar',
-                               'class': 'lorem'
+                               'class': 'lorem',
+                               'data-foo': 'data value'
                        },
                        $el = $( '<div>' ).attr( attrs );
 
-               assert.deepEqual( $el.getAttrs(), attrs, 'getAttrs() return object should match the attributes set, no more, no less' );
+               assert.propEqual( $el.getAttrs(), attrs, 'keys and values match' );
        } );
 }( jQuery ) );