0

Hello and thank you for your help in advance,

I am using a zoom plugin for jQuery that zooms images when mouse clicks . I want to put my script within skin so that it will work on all images within website. But I have a problem where I am wrapping an a tag around some images (I do not want these to zoom). So I tryed to come up with something that would select just the img without a tags around img.

 $(window).load(function(){
        
  $('img').filter(function(){
      //return !$(this).parents().hasClass('logo');this works but does not help me on other pages
      //return !$(this).parents().contains('a');//this does not work?
      return !$(this).closest('a');//this does not work 

}).wrap('<span style="display:inline-block"></span>')
    .css('display', 'block')
    .parent()
    .zoom({ on:'click' });
    
  • 2
    `return $(this).closest('a').length == 0` – Barmar Aug 19 '21 at 18:32
  • 1
    `$(this).closest('a')` returns a object which should always return true. Try to access the length of the jQuery object. like `$(this).closest('a').length` – Sysix Aug 19 '21 at 18:34
  • closest should return null, when no such element exists https://developer.mozilla.org/en-US/docs/Web/API/Element/closest however this would be plain js and no jquery – overflowed Aug 19 '21 at 18:35
  • 1
    @overflowed - That could be a bit confusing for the OP, since that's the DOM's `closest`, but they're using jQuery's. But you're right, they could use it: `return !this.closest("a");` instead of `return $(this).closest("a").length === 0;` – T.J. Crowder Aug 19 '21 at 18:36

0 Answers0