Answers for "assign style with javascript"

28

add style javascript

// Bad:
element.setAttribute("style", "background-color: red;");
// Good:
element.style.backgroundColor = "red";
Posted by: Guest on September-08-2020
0

Set CSS styles with javascript

var style = document.createElement('style');
  style.innerHTML = `
  #target {
  color: blueviolet;
  }
  `;
  document.head.appendChild(style);
Posted by: Guest on February-28-2022

Code answers related to "assign style with javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language