Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js create div

document.body.onload = addElement;

function addElement () {
  // create a new div element
  const newDiv = document.createElement("div");

  // and give it some content
  const newContent = document.createTextNode("Hi there and greetings!");

  // add the text node to the newly created div
  newDiv.appendChild(newContent);

  // add the newly created element and its content into the DOM
  const currentDiv = document.getElementById("div1");
  document.body.insertBefore(newDiv, currentDiv);
}
Comment

Create div with JS

const div = document.createElement('div');                     
// create a new div referenced in the variable 'div'
Comment

PREVIOUS NEXT
Code Example
Javascript :: align text into center of container react native 
Javascript :: javascript add script in head programmatically 
Javascript :: heroicons 
Javascript :: sequelize exclude attribute 
Javascript :: js remove dollar sign from string 
Javascript :: how to get the first character of a string in javascript 
Javascript :: track window resize in vue 
Javascript :: js get viewport width 
Javascript :: run react app in different port 
Javascript :: js find lowest number in array 
Javascript :: js stop form submit on enter 
Javascript :: generate random date in javascript 
Javascript :: react native transparent color 
Javascript :: wp_enqueue_script bootstrap 
Javascript :: is email js 
Javascript :: disable click event jquery 
Javascript :: get actual time jquery 
Javascript :: js method string remove extra spaces 
Javascript :: js pi 
Javascript :: javascript foreach get key and value 
Javascript :: check if array javascript 
Javascript :: javascript get body height 
Javascript :: next js get current url 
Javascript :: javasctipt unix timestamp from date 
Javascript :: javascript .split().reverse.join 
Javascript :: jquery scroll to top of div 
Javascript :: javascript set target blank 
Javascript :: To set the dropdown default value using jquery 
Javascript :: onchange select dropdown jquery 
Javascript :: how to clean modal on js in event hide 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =