How to set CSS for browser in JavaScript?

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

+4
source share
5 answers

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 a jQuery library.

+5
source

Since I have not yet seen an example of code that works without jQuery, here is one of them:

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

Note that the javascript property does not match the CSS property. Javascript properties do not use dashes and use camelCase instead.

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

+1
source

You can use .css

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

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

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

Use CamelCase as follows:

 WebkitBoxShadow 

Typically, a -<lowerCaseLetter> converted to the corresponding uppercase letter in the JS API.

0
source

All Articles