5

How to set style -webkit-box-shadow: 0px 0px 11px #000 to an element via JavaScript?

5 Answers 5

6

You can set it using the style object:

element.style['-webkit-box-shadow'] = '0px 0px 11px #000';

Demo: jsfiddle.net/S2eLb/

Edit:

To be clear, this method does not require the jQuery library.

Sign up to request clarification or add additional context in comments.

Comments

1

Since I haven't yet seen a code example that works without jQuery, here's one:

document.getElementById("test").style.webkitBoxShadow = "0px 0px 11px #000";

Note that the javascript property is not the same as the CSS property. The javascript properties do not use a dash and use camelCase instead.

And, a working demo here: http://jsfiddle.net/jfriend00/4LT7u/

1 Comment

You are mistaken. My answer doesn't use jQuery.
0

You can use the .css

$("divClass").css("-webkit-box-shadow","0px 0px 11px #000");

Links: http://api.jquery.com/css/

Comments

0
$('#elementname').css({
        '-webkit-box-shadow':'0px 0px 11px #000'})

Comments

0

Use CamelCase like this:

WebkitBoxShadow

Generally, a -<lowerCaseLetter> translates to the corresponding uppercase letter in the JS API.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.