Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

add element to body javascript

var elem = document.createElement('div');
elem.style.cssText = 'position:absolute;width:100%;height:100%;opacity:0.3;z-index:100;background:#000';
document.body.appendChild(elem);
Comment

How to add DOM elements to document body in javascript?

// The below code creates 3 paragraphs
// and adds them to document body

// 1. Create in-memory fragment to enhance performance
const fragment = document.createDocumentFragment();
const paragraphs = ["Paragraph1", "Paragraph2", "Paragraph3"];
// 2. Add paragraphs one by one to fragment
paragraphs.forEach((paragraph) => {
  const p = document.createElement("p");
  p.textContent = paragraph;
  fragment.appendChild(p);
});
// 3. Add resulting fragment to main DOM tree
document.body.appendChild(fragment);
Comment

PREVIOUS NEXT
Code Example
Javascript :: tailwind install nextjs 
Javascript :: the engine node is incompatible with this module 
Javascript :: dotenv jest 
Javascript :: js how to check typeof boolean 
Javascript :: jmeter mac 
Javascript :: console.dir depth 
Javascript :: express get cookie 
Javascript :: nodejs get current directory 
Javascript :: moment format 23 hour 
Javascript :: how to generate 6 random alphanumerals in js 
Javascript :: aos react 
Javascript :: default ordering false in datatable 
Javascript :: get current url angular 
Javascript :: array to set javascript 
Javascript :: js string pop last character 
Javascript :: how to select data attribute in javascript 
Javascript :: how to iterate table rows in javascript 
Javascript :: react native spinner 
Javascript :: js get array item by property 
Javascript :: js console.log color reset 
Javascript :: jest test array of objects 
Javascript :: how to check file extension in node js 
Javascript :: string to JSONobject android 
Javascript :: inject javascript to webpage 
Javascript :: datatable loading 
Javascript :: javascript friendly number format with commas 
Javascript :: fetch request to GraphQL 
Javascript :: typeface in gatsby 
Javascript :: expo create react native app 
Javascript :: angular build with configuration 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =