Find out how to Type an Aspect utilizing Javascript



If it is advisable type a component utilizing Javascript then you should use the type object to help all of your CSS wants.


    <p id="p1">Hi there World!</p>

      doc.getElementById("p1").type.coloration = "crimson";

    <p>The paragraph above was modified by a script.</p>


If it is advisable do that purely in a Javascript file itself, then:

// Get a reference to the factor
var myElement = doc.querySelector("#p1");

// Now you'll be able to replace the CSS attributes
myElement.type.coloration = "crimson";
myElement.type.backgroundColor = "yellow";

Word that the place CSS properties would use dashes to separate phrases, like background-color, Javascript as an alternative makes use of camel casing and drops the house.

Instance: background-color would change into backgroundColor.