Change drop-shadow with Javascript without jQuery

2.6k views Asked by At

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">

2

There are 2 answers

0
PitaJ On BEST ANSWER

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/

4
Uzbekjon On

Try this:

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

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