www.webdeveloper.com
Results 1 to 3 of 3

Thread: Porting getAttributeNode to getAttribute

  1. #1
    Join Date
    Apr 2013
    Posts
    2

    Porting getAttributeNode to getAttribute

    Hello,

    i am very new to javascript and need some help to get rid of some deprecated warnings coming from an old jquery release. I cannot update to a newer version yet so i need get rid of these warnings. Newer browsers throw out a warning not to use "getAttributeNode" and "nodeValue" anymore. It is recommended to use "getAttribute" and also "value" instead...

    I already tried myself but something is just not working. Maybe someone can help me? I would be so happy

    The first part is here

    Code:
    jQuery.each( text || this, function(){
    	jQuery.each( this.childNodes, function(){
    		if ( this.nodeType != 8 )
    			ret += this.nodeType != 1 ?
    				this.nodeValue :
    				jQuery.fn.text( [ this ] );
    	});
    });
    can i just replace with this.value ?

    Here are the other two function i am not sure how to rewrite them correctly

    Code:
    // browsers index elements by id/name on forms, give priority to attributes.
    if( jQuery.nodeName( elem, "form" ) && elem.getAttributeNode(name) )
    	return elem.getAttributeNode( name ).nodeValue;
    
    // elem.tabIndex doesn't always return the correct value when it hasn't been explicitly set
    // http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
    if ( name == "tabIndex" ) {
    	var attributeNode = elem.getAttributeNode( "tabIndex" );
    	return attributeNode && attributeNode.specified
    		? attributeNode.value
    		: elem.nodeName.match(/(button|input|object|select|textarea)/i)
    			? 0
    			: elem.nodeName.match(/^(a|area)$/i) && elem.href
    				? 0
    				: undefined;
    }
    Code:
    if ( !!document.getElementById( id ) ) {
    	Expr.find.ID = function(match, context, isXML){
    		if ( typeof context.getElementById !== "undefined" && !isXML ) {
    			var m = context.getElementById(match[1]);
    			return m ? m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : [];
    		}
    	};
    
    	Expr.filter.ID = function(elem, match){
    		var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
    		return elem.nodeType === 1 && node && node.nodeValue === match;
    	};
    }

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    Code:
    return elem.getAttributeNode( name ).nodeValue;
    is now
    Code:
    return elem.getAttribute( name )

    return m ? m.id === match[1] || typeof m.getAttributeNode !== "undefined" && m.getAttributeNode("id").nodeValue === match[1] ? [m] : undefined : [];[/code]

    can be (i think)
    Code:
    o = m ?   (m.id === match[1] || m.id === match[1] ? [m] : undefined ) : [];
    Code:
    Expr.filter.ID = function(elem, match){
    		var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id");
    		return elem.nodeType === 1 && node && node.nodeValue === match;
    	};
    could be
    Code:
    Expr.filter.ID = function(elem, match){
    		return elem.id;
    	};
    the other parts have so much to do with just reading attrib nodes i don't see how/why they should be converted; we should just fix the upstream calls so they are never used.

    i know this isn't perfect, but i hope this gets you closer.

  3. #3
    Join Date
    Apr 2013
    Posts
    2
    Many many thanks

    i will try your suggestions soon. As long as these warnings disappear i can sleep good again

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles