私はこれを行うためにjQueryを使用しています:
$element.find("*").each(function() {
var $this = $(this);
$this.removeAttr("style width align");
if ($this.is("embed")) {
$element.append("<div class='video'></div>");
$this.attr("width", 640).attr("height", 360).parent().appendTo("#" + element + " .video");
};
});
しかし、単純な for ループ ( jsPerf.each()
)と比較すると、jQuery のメソッドはかなり遅いと読んでいます。私の質問は、これを純粋な JS でどのように模倣できるかということです。a 内のすべての要素を検索し、ノードをループします。div
私はこれを検索しようとしましたが、見つけることができるのはjQueryの回答だけです-どこでも。
私は他のことを試しましたが、これはすべての子孫を選択するのと同じくらい近かったです:
var children = document.getElementById('id').getElementsByTagName('*');
for( var i = 0; i<children.lengtth; i++){
children[i].removeAttribute("style");
console.log(children[i]);
}