Skip to content

Instantly share code, notes, and snippets.

@fojas
Created August 6, 2010 04:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fojas/510815 to your computer and use it in GitHub Desktop.
Save fojas/510815 to your computer and use it in GitHub Desktop.
// jQuery extension for checking if css media query is supported
(function($){
$.mediaCheck = function (qry){
var ret,
style = document.createElement('style'),
id = 'mqc_'+Math.floor(Math.random()*100)+new Date().getTime(),
rules = document.createTextNode('@media '+qry+' {#'+id+'{visibility:hidden !important}}'),
head = $('head')[0];
body = $('body');
style.type = 'text/css';
if(style.styleSheet){style.styleSheet.cssText=rules.nodeValue;}
else{style.appendChild(rules);}
head.appendChild(style);
// div should not be seen
body.prepend('<div id="'+id+'" style="display:none" />');
ret = $('#'+id).css('visibility') == 'hidden';
//clean up
body.remove('#'+id);
return ret;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment