document.getElementsByClassName(variables);
<p>I'm trying to target an element through the use of two variables. I know how to do this for id's, but what I'm doing for classes doesn't seem to works. Does anyone have an idea what I'm doing wrong?</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta charset="UTF-8"&gt;
&lt;title&gt;&lt;/title&gt;
&lt;script&gt;
    var colour = purple;
    var number = 1;
    function check() {
        var x = document.getElementsByClassName(colour number);
        x[0].innerHTML = "Hello World!";
    }
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;div&gt;Username: &lt;/div&gt;
    &lt;input id="test" type="text" onblur="check()"&gt;
    &lt;div class="1 purple"&gt;one&lt;/div&gt;
    &lt;div class="2 red"&gt;two&lt;/div&gt;
    &lt;div class="3 blue"&gt;three&lt;/div&gt;
    &lt;div class="4 brown"&gt;four&lt;/div&gt;
    &lt;div class="5 orange"&gt;five&lt;/div&gt;
    &lt;div class="6 yellow"&gt;six&lt;/div&gt;
    &lt;div class="7 white"&gt;seven&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p><strong>Update</strong></p>

<p>I've tried both options but neither seems to work. This is the updated script.</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta charset="UTF-8"&gt;
&lt;title&gt;&lt;/title&gt;
&lt;script&gt;
    function check() {
        var colour = purple;
        var number = one;
        //var x = document.getElementsByClassName(colour + ' ' + number);
        var x = document.querySelector('.' + colour + '.' + number);
        x[0].innerHTML = "Hello World!";
    }
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;input id="test" type="text" onblur="check()"&gt;
    &lt;div class="one purple"&gt;one&lt;/div&gt;
    &lt;div class="two red"&gt;two&lt;/div&gt;
    &lt;div class="three blue"&gt;three&lt;/div&gt;
    &lt;div class="four brown"&gt;four&lt;/div&gt;
    &lt;div class="five orange"&gt;five&lt;/div&gt;
    &lt;div class="six yellow"&gt;six&lt;/div&gt;
    &lt;div class="seven white"&gt;seven&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Also note, this is only a test script. Once I get it working, I'll add a lot more divs, one for each color/number combination, so selecting on one class will not work.</p>