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

  • Home
  • SEARCH
  • 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 8851175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:05:22+00:00 2026-06-14T13:05:22+00:00

I am using this code to grab a class value from an a href:

  • 0

I am using this code to grab a class value from an a href:

<a href="" class="images/success.jpg">Click to get image</a>

<script>
$("#myMenu a").bind("click", function() {
  var myPic = $(this).attr("class");
  alert(myPic);
});
</script>

Everything working normal and smooth. Now I am using fancybox to load images and I have this code of fancy box that works normal also:

$.fancybox.open('images/success.jpg');

I am trying to pass the variable myPic into fancybox code but I cant make it.

So far I have tried this:

$.fancybox.open(myPic);
$.fancybox.open('myPic');

Is there any possibility to make it work?

  • 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-14T13:05:23+00:00Added an answer on June 14, 2026 at 1:05 pm

    There are always easier or more complicated ways to achieve the same result. Having a class="images/success.jpg" is not semantically appropriate. The easiest way to do it is to have that inside the href attribute like :

    <a class="fancybox" href="images/success.jpg">Click to get image</a>
    

    … and use the class to bind fancybox like

    $(".fancybox").fancybox();
    

    … that will also make sure that your link is accessible regardless if javascript is enabled or not (and more SEO friendly too.)

    However, you may have your own reasons (I hope) to pass the ref through a variable or through a different attribute (class in your example). To make your code neater, you may rather prefer to use a (HTML5) data-* attribute like :

    <a href="#nogo" data-path="images/success.jpg">Click to get image</a>
    

    … and get the value of the data-path attribute without requiring to set a variable and pass it to fancybox like :

    $("#menu a").on("click", function() {
        $.fancybox.open($(this).data("path"));
    });​
    

    Notice the use of jQuery .on() method that requires jQuery 1.7+

    See this FIDDLE for both working examples

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

Sidebar

Related Questions

I'm using this code to save images from a specific URL using Image::Grab .
I'm using this code: <script type='text/javascript'> $(document).ready(function () { //Check if url hash value
I am currently using this code to grab key-strokes, but I am missing e.g.
I'm using the code posted in this link TSplitter enhanced with grab bar ,
Using this code var html='<div class=somediv></div>'; var target=document.getElementById('contentArea'); target.appendChild(html); I'm getting Uncaught Error: NOT_FOUND_ERR:
When using this code: <script> $(document).ready(function () { $.getJSON(http://twitter.com/statuses/user_timeline/USERNAME.json?callback=?, function(data) { if(data[0].text.length > 107)
Im trying to get a form element value using closest. Here some example code.
Hi guys I'm using this wonderful class here to do a bit of code
I want to use this code to grab all methods from the assembly Mscorlib.dll
I'm using HtmlUnit in a Groovy script to get a csv file from 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.