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?

```js
function myFunction() {
    var x = document.getElementsByClassName("test").textContent;
$(".test").attr({
"style" : "background-color: + x + ;"
});
}
```

```css
.test{
  padding:5px;
  background-color:#555;
  color:white;
  display:inline-block;
}
```

```html
<div class="test">#999</div>
```