Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you set the box-shadow CSS property with JavaScript?

i have some variable like this in JavaScript:

var classattrib = "box-shadow:inset 12px 222px 2px 2px rgba(1,2,111,11);";
target.style['boxShadow'] = classattrib;

or:

target.style['webkitBoxShadow'] = classattrib;

But it is not working

//html

<div id="target">hello</div>

What am I doing wrong?

like image 731
Sarthak Shah Avatar asked Oct 23 '25 17:10

Sarthak Shah


1 Answers

Don't include the name of the property en the value, try like this:

var classattrib = "inset 12px 222px 2px 2px rgba(1,2,111,11)";
target.style.boxShadow = classattrib;
like image 105
bugarin Avatar answered Oct 25 '25 08:10

bugarin