Q:

Set style using pure javascript

I want to set body's background without jquery.
jquery : $('body').css('background','red');
Why this won't work in pure JS?
document.getElementsByTagName('body').style['background']  = 'red';

A:

var obj = document.getElementsByTagName('div')[0].style.backgroundColor = 'RED';
<div>sample</div>

A:

There are many ways you can set the background color.
  But getElementsByTagName does not return a single object, it's a collection of objects

document.body.style.backgroundColor = "green"; //javascript

document.getElementsByTagName("body")[0].style.backgroundColor = "green"; //another one

See the demo

