title: How to override Sizzle()
body: <p><strong>Having problem overriding Sizzle()</strong></p>
  
  <p>We encountered "SCRIPT70: Permission denied" exception in IE apparently, our fix is to hack our current version of jquery however we dont want to modify original Sizzle()   </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>(function ($) {
  
      $.fn.Sizzle = function (selector, context, results, seed) {
      var match, elem, m, nodeType,
          // QSA vars
          i, groups, old, nid, newContext, newSelector;
  
      // This try/catch seems to fix IE 'permission denied' errors as described here:
      // http://bugs.jquery.com/ticket/14535
      try {
          document === document; //may cause permission denied
      }
      catch (err) {
          document = window.document; //resets document, and no more permission denied errors.
      }
  
      if ((context ? context.ownerDocument || context : preferredDoc) !== document) {
          setDocument(context);
      }
  
      context = context || document;
      results = results || [];
  
      if (!selector || typeof selector !== "string") {
          return results;
      }
  
      if ((nodeType = context.nodeType) !== 1 &amp;&amp; nodeType !== 9) {
          return [];
      }
  
      if (!documentIsXML &amp;&amp; !seed) {
  
          // Shortcuts
          if ((match = rquickExpr.exec(selector))) {
              // Speed-up: Sizzle("#ID")
              if ((m = match[1])) {
                  if (nodeType === 9) {
                      elem = context.getElementById(m);
                      // Check parentNode to catch when Blackberry 4.6 returns
                      // nodes that are no longer in the document #6963
                      if (elem &amp;&amp; elem.parentNode) {
                          // Handle the case where IE, Opera, and Webkit return items
                          // by name instead of ID
                          if (elem.id === m) {
                              results.push(elem);
                              return results;
                          }
                      } else {
                          return results;
                      }
                  } else {
                      // Context is not a document
                      if (context.ownerDocument &amp;&amp; (elem = context.ownerDocument.getElementById(m)) &amp;&amp;
                          contains(context, elem) &amp;&amp; elem.id === m) {
                          results.push(elem);
                          return results;
                      }
                  }
  
                  // Speed-up: Sizzle("TAG")
              } else if (match[2]) {
                  push.apply(results, slice.call(context.getElementsByTagName(selector), 0));
                  return results;
  
                  // Speed-up: Sizzle(".CLASS")
              } else if ((m = match[3]) &amp;&amp; support.getByClassName &amp;&amp; context.getElementsByClassName) {
                  push.apply(results, slice.call(context.getElementsByClassName(m), 0));
                  return results;
              }
          }
  
          // QSA path
          if (support.qsa &amp;&amp; !rbuggyQSA.test(selector)) {
              old = true;
              nid = expando;
              newContext = context;
              newSelector = nodeType === 9 &amp;&amp; selector;
  
              // qSA works strangely on Element-rooted queries
              // We can work around this by specifying an extra ID on the root
              // and working up from there (Thanks to Andrew Dupont for the technique)
              // IE 8 doesn't work on object elements
              if (nodeType === 1 &amp;&amp; context.nodeName.toLowerCase() !== "object") {
                  groups = tokenize(selector);
  
                  if ((old = context.getAttribute("id"))) {
                      nid = old.replace(rescape, "\\$&amp;");
                  } else {
                      context.setAttribute("id", nid);
                  }
                  nid = "[id='" + nid + "'] ";
  
                  i = groups.length;
                  while (i--) {
                      groups[i] = nid + toSelector(groups[i]);
                  }
                  newContext = rsibling.test(selector) &amp;&amp; context.parentNode || context;
                  newSelector = groups.join(",");
              }
  
              if (newSelector) {
                  try {
                      push.apply(results, slice.call(newContext.querySelectorAll(
                          newSelector
                      ), 0));
                      return results;
                  } catch (qsaError) {
                  } finally {
                      if (!old) {
                          context.removeAttribute("id");
                      }
                  }
              }
          }
      }
  
      // All others
      return select(selector.replace(rtrim, "$1"), context, results, seed);
  };
  }(jQuery));</code></pre>
  </div>
  </div>
  </p>
  
  <p>Ref: <a href="https://bugs.jquery.com/ticket/14535" rel="nofollow">https://bugs.jquery.com/ticket/14535</a>
  <a href="https://bugs.jquery.com/ticket/14535#comment:11" rel="nofollow">https://bugs.jquery.com/ticket/14535#comment:11</a></p>