Creating a
with javascript createElement?

后端 未结 5 704
终归单人心
终归单人心 2020-12-30 19:41

I need to create a
tag dynamically with javascript.

var br = document.createElement(\'br\');

And

         


        
5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-30 20:12

    In reality, your code will still validate if your JavaScript doesn't exactly validate, because the validator only parses the processed HTML code, not the dynamic code created by JavaScript. If you cared, you could also use an innerHTML trick, or a document.createTextNode('
    ');
    if you wanted to force the XHTML version, but it is not recommended. document.createElement('br'); works perfectly fine.

提交回复
热议问题