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

Using Trello and Confluence to manage UX design project. Part 2

How do I use InVision

Using Trello and Confluence to manage UX design project. Part 1