0

The following excerpt from a fancybox script does not work under jquery 3.3.1. It works with jquery 1.11.0.

How would you rewrite this statement without removeAttribute, which is reported as not being a function?

a.support.opacity || 
(p.get(0).style.removeAttribute("filter"), 
f.get(0).style.removeAttribute("filter"));
Matthew S
  • 843
  • 2
  • 12
  • 26
  • Are you looking for [removeProperty](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleDeclaration/removeProperty) instead? – CertainPerformance Aug 30 '19 at 07:47
  • I don't know whether removeProperty or removeAttr would be proper. But per answer here: https://stackoverflow.com/questions/14344289/fancybox-doesnt-work-with-jquery-v1-9-0-f-browser-is-undefined-cannot-read (towards the bottom of the page) the attribute has to be replaced. I just don't understand how he handled the syntax. – Matthew S Aug 30 '19 at 07:54
  • 1
    Assuming `a` is a jQuery object then the issue is the use of [`support`](https://api.jquery.com/jQuery.support/). The documentation suggests using Modernizr for feature detection instead. – Rory McCrossan Aug 30 '19 at 07:55
  • Why don't you upgrade to the latest version of fancybox? – Janis Aug 30 '19 at 08:07
  • @Janis It's a script based on fancybox written by a third-party developer. Can't upgrade without rewriting the script. – Matthew S Aug 30 '19 at 08:09
  • 1
    Why do you think `removeAttribute` is deprecated in jquery? It's not a jquery method by the fact you've used `.get(0).style` (<- DOM element, not a jquery object) (and the fact is just a verbose name) https://developer.mozilla.org/en-US/docs/Web/API/Element/removeAttribute – freedomn-m Aug 30 '19 at 08:28
  • You're correct, I was thinking of .unbind, which also needed to be replaced. Corrected the original question. In any case, replacing removeAttribute with removeProperty solved the issue entirely. – Matthew S Aug 30 '19 at 08:37

1 Answers1

0

Replacing all instances of removeAttribute with removeProperty and .unbind with .off solved the issue entirely.

The old script now loads with jquery 3.3.1.

Matthew S
  • 843
  • 2
  • 12
  • 26