title: Changing background-color depending on content text
body: <p>i have a div and i want background color depending on div's context. example i type in two div class #999 and setting background color to #999. how can i do it with pure javascript?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function myFunction() {
      var x = document.getElementsByClassName("test").textContent;
  $(".test").attr({
  "style" : "background-color: + x + ;"
  });
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.test{
    padding:5px;
    background-color:#555;
    color:white;
    display:inline-block;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="test"&gt;#999&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>