为何removeAttribute API单独移除is属性时在outerHTML中不生效?
问题:移除Web Components的
is属性后outerHTML未同步更新 复现代码
var div = document.createElement("div"); var html = "<div id='issue' is='if'> some content </div>"; div.innerHTML = html; document.body.appendChild(div); var newDiv = document.querySelector("#issue"); newDiv.removeAttribute("id"); console.log(newDiv.outerHTML); newDiv.removeAttribute("is"); console.log(newDiv.getAttribute("is")); console.log(newDiv.outerHTML);
问题现象
调用removeAttribute移除is属性后,通过getAttribute("is")可确认该属性在DOM中已被移除(返回null),但outerHTML的输出结果里仍保留着is属性。已知is是Web Components的特殊属性,但移除属性后outerHTML未同步更新的表现不符合预期。
内容的提问来源于stack exchange,提问作者MOHAMED SIKKANDAR AFZAL M
相关产品推荐
相关产品推荐

