Menü schliessen
Created: September 15th 2021
Categories: IT Development,  JavaScript Development
Author: Marcus Fleuti

[WORKAROUND] How to fix j.get(...).style.removeAttribute is not a function / Fancybox not closing with newer JQuery

Tags:  Bug,  fancybox,  Javascript,  jQuery,  js,  workaround
Donation Section: Background
Monero Badge: QR-Code
Monero Badge: Logo Icon Donate with Monero Badge: Logo Text
82uymVXLkvVbB4c4JpTd1tYm1yj1cKPKR2wqmw3XF8YXKTmY7JrTriP4pVwp2EJYBnCFdXhLq4zfFA6ic7VAWCFX5wfQbCC

The Problem

After updating WordPress, which brings in it's own JQuery, i expirienced a bug. The WordPress had JQuery with JQuery Fancybox installed.
The bug says:

Uncaught TypeError: j.get(...).style.removeAttribute is not a function
    at HTMLDivElement.S (jquery.fancybox-1.3.4.pack.js:31)
    at HTMLDivElement.d.complete (jquery-min.js:3)
    at i (jquery-min.js:2)
    at Object.fireWith [as resolveWith] (jquery-min.js:2)
    at i (jquery-min.js:3)
    at n.fx.tick (jquery-min.js:3)

This bug happens because newer JQuery versions don't use style.removeAttribute anymore. So the style for closing the Fancybox-Popup cannot be attached anymore.

The Workaround

It is possible to alter the jquery.fancybox.js file in order to get the Fancybox closing event working again. For that you have to go into the jquery.fancybox.js file and change the following lines as seen below:

         _finish = function () {
             if (!$.support.opacity) {
-                content.get(0).style.removeAttribute('filter');
-                wrap.get(0).style.removeAttribute('filter');
+                $('#fancybox-content').css('filter', 0);
+                $('#fancybox-wrap').css('filter', 0);
             }

After you changed this file, just save it and you Fancybox should now be closing again.

You can also check this issue here: https://github.com/nvidoni/fancybox/issues/2