Advertisement
Alhadis

Detect browser support for :checked selectors

Mar 28th, 2013
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function checkedSelectorSupport(){
  2.     var d               =   document.documentElement;
  3.  
  4.     var t1              =   document.createElement("input");
  5.     t1.className        =   "checkedSelectorSupport";
  6.     t1.type             =   "checkbox";
  7.     t1.style.display    =   "none";
  8.     t1.checked          =   true;
  9.     d.appendChild(t1);
  10.  
  11.     var t2              =   document.createElement("div");
  12.     d.appendChild(t2);
  13.  
  14.     var t3          =   document.createElement("style");
  15.     t3.type         =   "text/css";
  16.     var rules       =   ".checkedSelectorSupport + *{display: none;}.checkedSelectorSupport:checked + *{display: block !important;}";
  17.     if(t3.styleSheet)   t3.styleSheet.cssText   =   rules;  //  IE 8 and earlier
  18.     else                t3.innerText            =   rules;
  19.     d.appendChild(t3);
  20.  
  21.     var style   =   t2.currentStyle ? t2.currentStyle : window.getComputedStyle(t2);
  22.     var result  =   style.display;
  23.  
  24.     d.removeChild(t1);
  25.     d.removeChild(t2);
  26.     d.removeChild(t3);
  27.  
  28.     return result;
  29. }
  30.  
  31. checkedSelectorSupport();   //  Will return FALSE in IE8 and earlier
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement