+ 13
Use :
// Adding gradient to body
document.body.style.backgroundImage = "linear-gradient(#DF2935, #FDCA40)";
// Adding gradient to div with id "color"
document.getElementById("color").style.backgroundImage = "linear-gradient(#DF2935, #FDCA40, #3772FF)";
+ 15
You can also refer to the below link here you can get further details about using linear gradient in css as well as in Javascript while scrolling down the page in detail
https://blog.idrisolubisi.com/how-to-create-beautiful-gradients-with-javascript