Replacement of .all() function for Browsers other than IE

隐身守侯 提交于 2019-12-24 09:46:43

问题


I am using following code

myEl = document.createElement("myElement") ;
//in a loop
myEl.innerHTML = myEl.innerHTML + currElement.outerHTML ; //some elements getting added to it
var newElement = myEl.all(idToSearch) ;

the last line is not working for browsers other than IE.. I am particularly using Chrome, is there any alternative for it???


回答1:


You can use querySelector() on elements that aren't yet attached to the document:

var newElement = myEl.querySelector("#" + idToSearch);



回答2:


all is a proprietary IE extension totally unsupported by standards compliant browsers.

Use document.getElementById() or start looking at libraries like jquery (which would also help with the innerHTML problems you're likely to encounter).



来源:https://stackoverflow.com/questions/4449069/replacement-of-all-function-for-browsers-other-than-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!