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 8274743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:50:15+00:00 2026-06-08T07:50:15+00:00

I have the following fancybox code: $(‘.fancybox’).fancybox({ ‘autoScale’ : false, ‘href’ : $(‘.fancybox’).attr(‘id’), ‘type’:’iframe’,

  • 0

I have the following fancybox code:

$('.fancybox').fancybox({
             'autoScale' : false,
             'href' : $('.fancybox').attr('id'),
             'type':'iframe',
             'padding' : 0,
             'closeClick'  : false,

//some other callbacks etc

the problem is I have twenty different A tag id’s on the page and I want the fancybox href attribute to take the id of the clicked element, ie the one that triggered the event.

I have tried several things, none of them have worked!

'href' : $(this).attr('id'),
'href' : $(this.element).attr('id'),

This seems so simple but anytime I plug in ‘this’ or similar nothing works.

  • 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-06-08T07:50:19+00:00Added an answer on June 8, 2026 at 7:50 am

    Without each() or click() simply add the beforeLoad callback to your script like this

    $(".fancybox").fancybox({
        autoScale: false,
        // href : $('.fancybox').attr('id'), // don't need this
        type: 'iframe',
        padding: 0,
        closeClick: false,
        // other options
        beforeLoad: function () {
            var url = $(this.element).attr("id");
            this.href = url
        }
    }); // fancybox
    

    NOTE: this is for fancybox v2.0.6+

    On the other hand, a more elegant solution is to use (HTML5) data-* attribute to set the href (it would look weird to set id="images/01.jpg" otherwise) so you could do :

    <a href="#" id="id01" data-href="images/01.jpg" ...
    

    and your callback

    beforeLoad: function(){
     var url= $(this.element).data("href");
     this.href = url
    }
    

    and use the id attribute for what is meant for.


    EDIT : The best is to use the special data-fancybox-href attribute in your anchor like :

    <a id="item01" data-fancybox-href="http://jsfiddle.net" class="fancybox" rel="gallery"  href="javascript:;">jsfiddle</a>
    

    and use a simple script without callback like

    $(".fancybox").fancybox({
        // API options 
        autoScale: false,
        type: 'iframe',
        padding: 0,
        closeClick: false
    });
    

    See JSFIDDLE

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

Sidebar

Related Questions

I have the following code which I use to match fancybox possible elements: $('a.grouped_elements').each(function(){
i have opened fancy box with following code $(#tip5).fancybox({ 'width': 400, 'height': 370, 'enableEscapeButton'
I have the following: in header: <script type=text/JavaScript> $(document).ready(function() { $(.modal).fancybox({ // for modals
I have the following Fancybox declarations in my page: <script type=text/javascript> $(document).ready(function() { $(.fancybox).fancybox().hover(function()
I have following HTML menu: <ul> <li><a href=index.html>Index Page</a></li> <li><a href=#some-page>Some Page</a></li> </ul> Let
I have following link in a.aspx file: <a href=a.htm target=iframe>A</a> I want to set
I have following code to show or hide some labels depending if a radiobutton
Have the following in an fancybox ajax call $.ajax({ type: 'POST', url: 'sendmesse.php', data:
I'm using Fancybox 1.3.4 with ASP.NET MVC 3. I have following link : <a
I'm using Fancybox and Zend. Hope the following is clear. On www.example.com/template/edit/id/3 I have

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.