替换IE以外的浏览器的.all()函数 [英] Replacement of .all() function for Browsers other than IE
本文介绍了替换IE以外的浏览器的.all()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码
myEl = document.createElement("myElement") ;
//in a loop
myEl.innerHTML = myEl.innerHTML + currElement.outerHTML ; //some elements getting added to it
var newElement = myEl.all(idToSearch) ;
最后一行不适用于IE以外的浏览器。
我特别使用Chrome,是否有任何替代方法???
the last line is not working for browsers other than IE.. I am particularly using Chrome, is there any alternative for it???
推荐答案
您可以使用 querySelector()
:
You can use querySelector()
on elements that aren't yet attached to the document:
var newElement = myEl.querySelector("#" + idToSearch);
这篇关于替换IE以外的浏览器的.all()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文