For example, there is such a problem.
In this div, add a playlist. This list is added using innerHTML.
I don’t need to worry about the complicated code in the middle. Now I want to take out the div named playing. It is easy to think of using
getElementsByName
. However, what is very strange is that it cannot be obtained under IE. getElementById works perfectly.
The following is a good solution:
function GetElementsByName(tag, name) {
var elem = document.getElementsByTagName(tag);
var arr = [];
var index = 0;
var l = elem.length;
for(var i = 0; i < l; i )
{
var att = elem[i].getAttribute("name");
if(att == name) {
arr[index] = elem[i];
}
}
return arr;
}
Changed to this function, you can get it. Just one more parameter is needed.
I don’t know if bloggers have any other solutions. This solution is not perfect. Be sure to leave a message in the comments.