1

I want to add the style -webkit-filter: drop-shadow(5px 5px 5px #222); in JavaScript without jQuery.

I want create a shadow for png transparent image duration with CSS transform.

This code is not working correctly:

var scscsc = document.getElementById('scscsc');
scscsc.setAttribute("style", "-webkit-filter: drop-shadow(5px 5px 5px #222);");
scscsc.style.transform = "rotate(216deg)";
body {
  margin: 0px;
  padding: 0px;
  text-align: center;
}
img {
  position: absolute;
  top: 0;
  left: 0;
}
<img src="http://sirati.info/tmp/ss.png" id="scscsc">
PitaJ
  • 12,969
  • 6
  • 36
  • 55

2 Answers2

2

Uzbekjon's answer will only work if that is the only CSS property you are using. It's preferable to set inline CSS using the style property of the element like so:

var elt = document.getElementById("#your-element-id");

elt.style.setProperty("-webkit-filter", "drop-shadow(5px 5px 5px #222)");

Edit: here is a working JSfiddle demonstrating this works

https://jsfiddle.net/w4n024b4/

PitaJ
  • 12,969
  • 6
  • 36
  • 55
0

Try this:

var elt = document.getElementById("#your-element-id");

elt.setAttribute("style", "-webkit-filter: drop-shadow(5px 5px 5px #222);");
Uzbekjon
  • 11,655
  • 3
  • 37
  • 54