Setting a input type color to a ja variable

I have a <p>Choose your color: <input type="color" id="colorInput"></p> and I want to set It as a js variable then use document.getElementById() to set the color chosen to the background color of <h1 class='title-main' onclick='editTitle()' id='title'>Welcome to your JohnnySite</h1>
Repl link:

(This is the second time is made this post because the other time it glitched and broke)

You can do this:

<p>Choose your color: <input type="color" id="colorInput" onchange="changeBack(this);"></p>
    function changeBack(color_input) {
        var color = color_input.value;
        document.getElementById('title').bgcolor = color;

It may be more efficient to use document.getElementById('title').style.backgroundColor = color but Iā€™m not sure.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.