How to append html code using javascript and php

append html code using javascript and php, In this example I am going to show you how to add the dynamic HTML code into Document using javascript and PHP.

How to append html code using javascript and php

01<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
02 
03$random_id = 125845465; // PUTTING SOME RANDOM ID YOU CAN USE YOURSELF.
04 
05$DYNAMIC_HTML = '<div>
06<b>Sponsored Links</b>
07 
08<div>
09 12px;font-weight:bold;" href="http://www.ucoz.com/" rel="nofollow">Create a website for free - uCoz
10 
11Build a website quickly and easily
12Customizable templates and graphics
13 
14</div>
15 
16<div>
17 12px;font-weight:bold;" href="http://www.purabtech.in/files/domain_names/">$1.99 Domain Names
18 
19 With every new non-domain purchase thru <a href="http://www.purabtech.in/files/domain_names/" rel="nofollow">wordpressapi</a>, you get a domain name for only $1.99.
20</div>
21 
22<div>
23 12px;font-weight:bold;" href="http://www.purabtech.in/files/" rel="nofollow">FREE Hosting!
24 
25 With every domain you register with <a href="http://www.purabtech.in/files/" rel="nofollow">wordpressapi</a> you get FREE hosting.
26</div>
27</div>';
28 
29 $HTML = "var objHead = document.getElementsByTagName('head');
30 var objCSS = objHead[0].appendChild(document.createElement('link'));
31 objCSS.id = '.$random_id.';
32 objCSS.rel = 'stylesheet';
33 objCSS.href = 'http://YOURSITE/STYLE.css';
34 objCSS.type = 'text/css';";
35 
36 $HTML .= '
37 var WORDPRESAPI_html_'.$random_id.' = document.createElement("div");
38 WORDPRESAPI_html_'.$random_id.'.id = "WORDPRESAPI_html_'.$random_id.'";
39 WORDPRESAPI_html_'.$random_id.'.style.position = "absolute";
40 WORDPRESAPI_html_'.$random_id.'.style.zIndex = "100";
41 WORDPRESAPI_html_'.$random_id.'.style.left = "0px";
42 WORDPRESAPI_html_'.$random_id.'.style.top = "0px";
43 WORDPRESAPI_html_'.$random_id.'.style.visibility = "hidden";
44 WORDPRESAPI_html_'.$random_id.'.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=100)";
45 WORDPRESAPI_html_'.$random_id.'.innerHTML = "'.addcslashes($DYNAMIC_HTML,"\\\'\"&\n\r<>").'";
46 document.body.appendChild(WORDPRESAPI_html_'.$random_id.');';
47 
48echo $HTML;
49 
50?>

In this code if you observe then following line is very important.

1WORDPRESAPI_html_'.$uniqid.'.innerHTML = "'.addcslashes($HTML,"\\\'\"&\n\r<>").'";
How to append html code using javascript and php
How to append html code using javascript and php

Whenever you are using javascript and PHP both together then use following way to push your HTML in Dom.