Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7429225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:56:08+00:00 2026-05-29T08:56:08+00:00

I use jquery fancybox 1.3.4 as pop form. but I found fancybox can’t bind

  • 0

I use jquery fancybox 1.3.4 as pop form.

but I found fancybox can’t bind to element dynamic added. for example when I add a html element to current document.

like this:
first I append a element to body use jquery,

  $(document.body).append("<a href="home/index" class="fancybox"/>");

and I call fancybox,

  $(".ajaxFancyBox").fancybox({padding: 0});

but fancybox don’t work with dynamic added element.

and I can’t call fancybox from this element?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:56:09+00:00Added an answer on May 29, 2026 at 8:56 am

    The easiest way to bind fancybox (v1.3.x) to dynamically added elements is:

    1: Upgrade to jQuery v1.7.x (if you haven’t yet)

    2: Set your script using jQuery API on() + the focusin event.

    To make it work you need to find the parent element of your elements with class="ajaxFancyBox" as per your code above (or the parent of the parent as you need it) and attach jQuery on() to it so for example, having this html:

    <div id="container">
     <a class="ajaxFancyBox" href="image01.jpg">open image 01</a>
     <a class="ajaxFancyBox" href="image02.jpg">open image 02</a>
    </div>
    

    .. we will apply on() and focusin event to the element with id="container" (the parent) as in the example above, like:

    $("#container").on("focusin", function(){
     $("a.ajaxFancyBox").fancybox({
      // fancybox API options here
      'padding': 0
     }); // fancybox
    }); // on
    

    You can apply any fancybox option as you need. Additionally you may have different scripts for different type of content (inside the on() method) like:

    $("#container").on("focusin", function(){
     $("a.ajaxFancyBox").fancybox({
      // fancybox API options here
      'padding': 0
     }); // fancybox
     $("a.iframeFancyBox").fancybox({
      // fancybox API options here
      'padding': 0,
      'width': 640,
      'height': 320,
      'type': 'iframe'
     }); // fancybox
    }); // on
    

    IMPORTANT: the example above won’t work like that on Chrome. The workaround is to add the tabindex attribute to all of your elements bound to fancybox like

    <div id="container">
     <a tabindex="1" class="ajaxFancyBox" href="image01.jpg">open image 01</a>
     <a tabindex="1" class="ajaxFancyBox" href="image02.jpg">open image 02</a>
    </div>
    

    that solves the issue and will work (as far as I know) in most browsers including IE7+.

    See my demo page here

    UPDATE: March 07, 2012.

    I was told that this method only works when you add new content to the page but not when you replace the content of the page.

    The method actually works on either of the two scenarios mentioned above. Just make sure that the new replacing content is also loaded inside the container where you applied the .on() method.

    See demo

    The tabindex workaround for Chrome also applies.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I use FancyBox or JQuery to create multiple pop-up DIVs that all
I would like to use jQuery Fancybox or Lightbox to load a contact form
I am trying to have a pop up video player. Would use fancybox, but
I'm trying to use jQuery's $(this) inside of Fancybox's onComplete event, but I'm running
I have the jQuery fancybox 2 plugin in use on my site. In development
I use jQuery to do AJAX calls. But specialchars like ÆØÅ (danish letter) comes
I'm experiencing a little bugger using the fancybox jquery plugin. I want to use
Trying to use JQuery Easing plugin in my wordpress but its giving me following
I am making use of the JQuery fancy box - in this pop up
I'd like to use the jQuery plugin Fancybox on my site - for the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.