javascript create element with attributes
var element = document.createElement("span");
element.setAttribute("style", "color: red");
document.body.appendChild(element);document.getElementsByTagName("H1")[0].setAttribute("class", "democlass");document.body.onload = addElement;
function addElement () {
// create a new div element
var newDiv = document.createElement("div");
// and give it some content
var 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
var currentDiv = document.getElementById("div1");
document.body.insertBefore(newDiv, currentDiv);
}
Also in JavaScript:
- compare two arrays javascript
- nangular make window available
- javascript dynamic table row add
- check textbox value on ng-change value == in angular
- map function javascript
- axios react
- js kill process
- react split array into chunks
- nextjs react testing library typescript
- use .map to count length of each element in an array
- code convert java script to jQuery
- js detect device
- potencia em javascript
- javascript get all cookies
- angular for each
- javascript object string property
- fs.writeFileSync in pdfDocument
- uncaught TypeError: Bootstrap's JavaScript requires jQuery. jQuery must be included before Bootstrap's JavaScript electron
- /runtime.d7bbc2cdb230ca3d1157.js
- nodejs format text
- how to delete element in array in javascript
- unterminated character class react native
- Unexpected end of JSON input while parsing near '...fcd15e632426a1be","ta'
- how to play sound on load js