Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Attempt at detecting CSS `:target` support
// Determine whether or not we need to run fallback code by testing for `:target` support.
var targetSupport = ( function targetSupport(){
var iframe = document.createElement( 'iframe' );
var body = document.getElementsByTagName( 'body' )[ 0 ];
var doc;
var outcome;
iframe.tabindex = -1; = 'none';
body.appendChild( iframe );
doc = iframe.contentWindow.document;
doc.write( '<body id="x"><style>:target{display:none}</style>' );
doc.location.hash = 'x';
if( doc.getElementById( 'x' ).style.display === 'none' ){
outcome = true;
else {
outcome = false;
body.removeChild( iframe );
return outcome;
}() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.