views:

43

answers:

1

Hello

I'm creating a layout in full css. However, some browser (such as IE6) do not support box-shadow (.. and -webkit-box-shadow or -moz-box-shadow). I would like to check if it's not supported and then add other styles.

How's this possible in jQuery?

Martti Laine

+3  A: 
var check = document.createElement('div');

var shadow = !!(0 + check.style['MozBoxShadow']);
if(shadow)
   alert('moz-box-shadow available');

That is the doing-it-yourself way. Other reliable way is the modernizr library, which does feature detection for you.

http://www.modernizr.com/

No jQuery needed at all here.

jAndy
-1 for DIY. +1 for Modernizr....net effect 0. :P
Stefan Kendall
@Stefan: So what exactly is the -1 for? :p
jAndy
Not sure what issue @Stefan has with the DIY. The same check would probably be done for the `WebkitBoxShadow` and `boxShadow`, but it's not much of a stretch to figure that out.
patrick dw
It's like writing your own GCD function, when one exists. In case the check for boxshadow changes in the future, Modernizr could be updated to support this change. Any code you write yourself that exists in a library is bad code.
Stefan Kendall
@Stefan: are you serious ? You'd suggest someone, who just needs to make one or two feature detections (which is about 30 bytes?) to use a lib that takes like 2k, 3k, 10k whatever? Don't get me wrong, I like modernizr, but for just one check is overkill. It's like using jQuery to select an element.
jAndy
Yes, jQuery SHOULD be used to select elements. It's a one-time static hit, and if you point to a proper CDN you're likely to get a cache hit. Modern libraries are incredibly small when compressed, and this is an egregious copying of code. 5KB is NOT a significant amount of space. You're arguing to not use libraries, due to the potential "bloat". Copying code has a far more terrible impact on code longevity.
Stefan Kendall
@Stefan: I guess we are looking at things differently, so whatever.
jAndy