{"id":12010,"date":"2022-03-10T06:05:20","date_gmt":"2022-03-10T11:05:20","guid":{"rendered":"http:\/\/local.brightwhiz\/?post_type=snippets&p=12010"},"modified":"2022-03-10T06:05:22","modified_gmt":"2022-03-10T11:05:22","slug":"javascript-add-element-to-the-dom","status":"publish","type":"snippets","link":"http:\/\/local.brightwhiz\/snippets\/javascript-add-element-to-the-dom\/","title":{"rendered":"JavaScript add Element to the Dom"},"content":{"rendered":"\n
JavaScript add element to the Dom code.<\/p>\n\n\n\n
\/\/ create a temporary dom element\nvar temp = document.createElement('div'); \n\n\/\/ Add content to div\ntemp.innerHTML = '<p>some html string<\/p>'; \n\n\/\/select the element to append to\nvar element = document.getElementById("myElementID");\nelement.appendChild(temp);\n\n\/\/alternate\nvar element = document.querySelector('#some-element');\nelement.appendChild(temp);<\/code><\/pre>\n","protected":false},"comment_status":"open","ping_status":"closed","template":"","meta":[],"categories":[4,953,27,15,28,16],"tags":[954,328,433,449,471,472,544,591,635,638],"yoast_head":"\nJavaScript add Element to the Dom [Snippet]<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n