I've got the following JavaScript snippet:
document.getElementById("imgA").style.box-shadow = "0 0 5px #999999";
The hyphen in box-shadow
is causing the JavaScript engine to throw an invalid assignment exception (in Firefox). Doing "box-shadow"
or 'box-shadow'
doesn't work. Is there a good way around this without using jquery's .css()
method?
The box-shadow CSS property adds shadow effects around an element's frame. You can set multiple effects separated by commas.
Like in other comments set first two values to 0px in order to have even shadow on all sides.
You can use style["boxShadow"]
or style.boxShadow
.
document.getElementById("foo").style["boxShadow"] = "0 0 5px #999999";
<div id="foo">12123123</div>
CSS properties with a -
are represented in camelCase
in Javascript
objects. So you dont need a hyphen -
just write boxShadow
document.getElementById("shadow").style["boxShadow"] = "0 0 5px #999999";
<div id="shadow">Tushar </div>
Use boxShadow
document.getElementById("imgA").style.boxShadow = "0 0 5px #999999";
document.getElementById('redbox').style.boxShadow = "0 0 3px #000";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With