Answers for "how to add css using js"

12

javascript modify css

//Pure JavaScript DOM
var el = document.getElementById("elementID");
el.style.css-property = "cssattribute";

//When doing A CSS property that have multiple words, its typed differently
//Instead of spaces or dashes, use camelCase
//Example:
el.style.backgroundColor = "blue";

//Make sure before using jQuery, link the jQuery library to your code
//JavaScript with jQuery
//jQuery can use CSS property to fid=nd an element
$("#elementID").css("css-property", "css-attribute");

//On jQuery, the CSS property is typed like normal CSS property
//Example: 
$("#elementID").css("background-color", "blue");

//If you want multiple property for jQuery, you can stack them on one code
//instead of typing each attribute
//Example: 
$("#elementID").css({"css-property": "css-attribute", "css-property": "css-attribute"});

//you can also make them nice by adding line breaks
//Example: 
$("#elementID").css({
  "css-property": "css-attribute",
  "css-property": "css-attribute"});
//You can add as much CSS property and attribute as you want
//just make sure, always end it with a comma before adding another one
//the last property doesn't need a comma
Posted by: Guest on April-28-2020
2

add css in javascript

document.getElementById("demo").style.display = "none";
Posted by: Guest on November-09-2020
7

how to give css style in javascript

document.getElementById("myH1").style.color = "red";
Posted by: Guest on September-18-2020
0

add css style sheet with javascript

<head>

<script>
function myFunction() {
  var x = document.createElement("LINK");
  x.setAttribute("rel", "stylesheet");
  x.setAttribute("type", "text/css");
  x.setAttribute("href", "styles.css");
  document.head.appendChild(x);
}
myFunction()
</script>

</head>
Posted by: Guest on June-12-2020
0

how to change an element in a different elements code css

/*If the cube is directly inside the container:*/

#container:hover > #cube { background-color: yellow; }

/*If cube is next to (after containers closing tag) the container:*/

#container:hover + #cube { background-color: yellow; }

/*If the cube is somewhere inside the container:*/

#container:hover #cube { background-color: yellow; }

/*If the cube is a sibling of the container:*/

#container:hover ~ #cube { background-color: yellow; }
Posted by: Guest on November-12-2020
-1

how to add css styles in javascript

const style = document.createElement(`style`);
    // this.shadowRoot.appendChild(this.templateContent);
    // log(`this.shadowRoot`, this.shadowRoot);
    style.setContent = `
      .run {
        width: 100px;
        height: 100px;
        background: url(https://www.boston.com/wp-content/uploads/2016/05/yuge_anger.png) 0 0;
        animation: run 500 step(6) infinite;
      }
      @keyframes run {
        from {
          background-position: 0 0;
        }
        to {
          background-position: -600px 0;
        }
      }
    `;
Posted by: Guest on July-04-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language