javascript document.write() removes the html from page and display result in a blank page [duplicate]

岁酱吖の 提交于 2019-12-01 14:52:56
suresh.g

You can use innerHTML in javascript. It use to insert data to particular div without affecting page contents.

Example:

var results = "";
for(var i=1;i<=10;i++)
{
     results += "<div class='pagination_btn'>"+i+"</div>";
}
document.getElementById("your result show div id").innerHTML = results;

you can specify $('.pagination_btn').bind("click")... inside your document.ready

Use innerHtml to change text of a specific element.

HTML

<div id="container"></div>

javascript

document.getElementById('container').innerHTML += '<div>content</div>';

or you can use jQuery library, life will be much easier:

$("#container").append("<div>content</div>");

try this

document.getElementsByTagName('body').innerHTML += '<div id="parent" class="pagination_btn_cont">';

for (i=1;i<=page;i++)
{ 
 document.getElementById('parent').innerHTML = "<div class='pagination_btn'>"+i+"</div>";
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!