TypeError: $ (...). Parent (...). Size is not a function

I have a basic script that allows me to click on the background of a website, excluding #content .

After upgrading jQuery version to version 3.1.0, I get this error: TypeError: $(...).parents(...).size is not a function .

 <script type="text/javascript"> $(function() { $("#background").click(function(e) { if (e.target.id == "wrapper" || $(e.target).parents("#wrapper").size()) { // do nothing } else { window.open('http://example.com'); } }); }) </script>` 

I do not know how to fix this. jQuery loads properly. Please, help.

+6
source share
1 answer

size() deprecated many years ago and removed in version 3 ... use length instead

 if (e.target.id == "wrapper" || $(e.target).parents("#wrapper").length) 

All you had to do was look at the size() docs in this

+24
source

All Articles