Find out how to Type an Aspect utilizing Javascript

0
10
Adv1


Adv2

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

<html>
  <physique>

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

    <script>
      doc.getElementById("p1").type.coloration = "crimson";
    </script>

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

  </physique>
</html>

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.

Adv3