Get Element By Tag and Name attribute (getElementsByName sort of)

Cross browser function to get element(s) by "name" attribute.


/** getElementsByTagAndName: to avoid missing getElementsByName in IE */
function getElementsByTagAndName(tag, name) {
    var elem = document.getElementsByTagName(tag);
    var arr = new Array();
    for(i = 0, iarr = 0; i < elem.length; i++) {
        att = elem[i].getAttribute("name");
        if(att == name) {
            arr[iarr] = elem[i];
            iarr++;
        }
    }
    return arr;
}

Comments

  1. Thanks for the script. Very useful.

    ReplyDelete
  2. Hey, I saw your profile on dancePartner.com(my nick there is larabonita )if u're interested write me at 4katerina@gmail.com :)

    ReplyDelete

Post a Comment

Popular posts from this blog

Data visualization for Roadmap Microsite (Angular and D3.js)

Conceptual design

Four tools for prototyping: Sketch, Figma, Principle, and FramerX