<p>This was my first version, didn't work in mobile.</p>
<pre>var calcSupport1 = !!$('<div/>').css('width', 'calc(1px)').width();</pre>
<div id='result1'></div>
<p>Since it seems that this may not work with an element that hasn't been injected into the DOM, it always reported false. So, this is what I came up with instead.</p>
<pre>var calcSupport2 = !!$('head').css('width', 'calc(1px)').width();</pre>
<div id='result2'></div>
<p>You could just inject the div into the DOM so that it'll play nice with mobile. There will just an empty div in the body of the page.</p>
<pre>var calcSupport3 = !!$('<div/>').appendTo('body').css('width', 'calc(1px)').width();</pre>
<div id='result3'></div>
<p>But I like the simplicity of using the head element since we won't care if it has size properties applied.</p>
JavaScript
var calcSupport1 = !!$('<div/>').css('width', 'calc(1px)').width();
var calcSupport2 = !!$('head').css('width', 'calc(1px)').width();
var calcSupport3 = !!$('<div/>').appendTo('body').css('width', 'calc(1px)').width();
$('#result1').text(calcSupport1);
$('#result2').text(calcSupport2);
$('#result3').text(calcSupport3);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.