jQuery Fancybox 2.0.5 syntax error

I’m trying to implement Fancybox v2.0.5 into my page. Before this, i used 1.3.4 without a problem.

The problem is, when .fancybox() has been called on an element, i get this error whenever i click anywhere on the page:

  • FancyBox returning “The requested content cannot be loaded. Please try again later.” with link
  • Make fancybox elements stay in their position
  • Fancybox: Get id of clicked anchor/element
  • parent.parent.window.location.href is not working
  • Close fancybox popup when youtube video finish
  • Javascript and jQuery (Fancybox) question
  • Uncaught Error: Syntax error, unrecognized expression: )
    

    I’ve been able to make out that it has something to do with the fact that i’m wrapping certain elements in anchors, calling it like this:

    var $a = $("<img/>", {src:"path_to_img", alt:"YT afbeelding"})
                    .wrap('<a href="#yt_editor" class="yt_vid" rel="'+video_id+'" />')
                    .parent()
                    .fancybox();
    

    Anyone have any idea how to fix this?

  • Pikachoose/Fancybox Integration - navigation arrows on the lightbox
  • How can I use $(this) inside of Fancybox's onComplete event?
  • Fancybox - Implementing afterClose callback
  • Fancy Box 2 - Window jumping to top on click
  • Opening a fancyBox with a certain aspect ratio
  • How to change Fancybox preloader image?
  • One Solution collect form web for “jQuery Fancybox 2.0.5 syntax error”

    Personally I’d call this a bug in the plugin. The problem lies in the way you’re getting setting up the initialization call. I think this should work:

    $('.yt_img').wrap("<a href='#' class='yt_img_wrapper'/>");
    $('.yt_img_wrapper').fancybox();
    

    The problem is that the plugin expects to be able to use the “selector” internal jQuery value as a way to get to the element(s) on which the plugin was called, and (in my opinion) that’s just a poor design decision. The selector, in your case, is “.yt_img.parent()”, which is not a valid selector; that’s what’s triggering the syntax error exception.

    edit — it’s already logged as issue #173 in the GitHub bug list for Fancybox.