Basic change color

color change by setAttribute

by Megi93

HTML

<h1 id="page-title">This is the best website.</h1>

<p id="my-first-paragraph">Seriously.</p>

<p id="another-paragraph">It's great.</p>

<button onclick="changeToRed()">Make everything red!!!</button>

<button onclick="changeToBlue()">Make everything blue!!!</button>

JavaScript

var title = document.getElementById("page-title");
var para = document.getElementById("my-first-paragraph");
var paraTwo = document.getElementById("another-paragraph");

function changeToRed() {
    title.setAttribute("style", "color: red;");
    para.setAttribute("style", "color: red;");
    paraTwo.setAttribute("style", "color: red;");
}

function changeToBlue() {
    title.setAttribute("style", "color: blue;");
    para.setAttribute("style", "color: blue;");
    paraTwo.setAttribute("style", "color: blue;");
}