admin 管理员组文章数量: 1086019
I want to display my document.write("something important");
into a specific div with specific id.
Im my HTML, I have a div <div class="col-lg-4" id="print"> ... </div>
In my JavaScript, I have a loop.
for(var i = 0; i < L; i++) {
document.write(
navigator.plugins[i].name +
" | " +
navigator.plugins[i].filename +
" | " +
navigator.plugins[i].description +
" | " +
navigator.plugins[i].version +
"<br><hr><br>"
);
}
What is the most efficient way to display them in my div ?
I want to display my document.write("something important");
into a specific div with specific id.
Im my HTML, I have a div <div class="col-lg-4" id="print"> ... </div>
In my JavaScript, I have a loop.
for(var i = 0; i < L; i++) {
document.write(
navigator.plugins[i].name +
" | " +
navigator.plugins[i].filename +
" | " +
navigator.plugins[i].description +
" | " +
navigator.plugins[i].version +
"<br><hr><br>"
);
}
What is the most efficient way to display them in my div ?
Share Improve this question edited Mar 18, 2015 at 19:05 iori asked Mar 18, 2015 at 18:46 ioriiori 3,50615 gold badges49 silver badges79 bronze badges2 Answers
Reset to default 4I would remend not using document.write
, especially after the page has loaded. It can lead to unexpected results. Just use this method:
document.getElementById('print').innerHTML = "something important";
If, however, you did not want to replace the whole innerHTML
, you could append something to it:
document.getElementById('print').insertAdjacentHTML('beforeend', "something added");
Update
Here is an example with a loop:
var elem = document.getElementById('print'),
L = navigator.plugins.length;
for(var i = 0; i < L; i++) {
elem.insertAdjacentHTML('beforeend',
navigator.plugins[i].name +
" | " +
navigator.plugins[i].filename +
" | " +
navigator.plugins[i].description +
" | " +
navigator.plugins[i].version +
"<br><hr><br>"
);
}
JS Fiddle Demo
man!
I think that what you want to do is update the content of the element, right? If so:
document.getElementById('print').innerHTML = something important
I hope I have helped you
本文标签: javascriptHow to display documentwrite in a specific div with specific idStack Overflow
版权声明:本文标题:javascript - How to display document.write in a specific div with specific id? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744017925a2519266.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论