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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:55:57+00:00 2026-06-17T21:55:57+00:00

I have been attempting to create a dynamic jQuery image gallery that does not

  • 0

I have been attempting to create a dynamic jQuery image gallery that does not require the user to be taken to a new destination when they click a link. It can be found here – http://the-session.co.uk/JSgallery/

I have created the showPic function which takes 2 arguments – the event object and an element node object (a specific element that is clicked on with a class of link) . The source variable uses the .attr() method and acts as a “getter” to get the src attribute of the element node passed to the showPic function.

I have then stored the <img id="placeholder"> in a variable called gallery. The idea was then to set the src attribute of gallery to the src from the source variable.

I have then used event.preventDefault(); so that the the default action of the event will not be triggered. However the elements are still taking the user to a new destination which is not desired.

The final step was to select .link (the <a> elements) and then use the .on method so that when a user clicks an anonymous function is invoked. The showPic function is then called and it is passed the specific element that was clicked on using $(this).

Currently the code is not working and I do not understand why. Any suggestions?

function showPic (event, el) {
    var source = el.attr('source'); // getter
    var gallery = $('#placeholder'); // <img id="placeholder">
    gallery.attr('src', source); // setter
    event.preventDefault();
}

$('.link').on('click', function() {  
        showPic($(this));
});
  • 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-17T21:55:58+00:00Added an answer on June 17, 2026 at 9:55 pm

    You’ll need to pass the event as well, when inside a function like that :

    function showPic (event, el) {
        event.preventDefault();
        $('#placeholder').attr('src', el.attr('source'));
    }
    
    $('.link').on('click', function(event) {  
        showPic(event, $(this));
    });
    

    On the other hand if you reference the function directly the event will be passed, and you can use event.target to get the clicked element, if that is the same as the bound element:

    function showPic (event) {
        event.preventDefault();
        $('#placeholder').attr('src', $(event.target).attr('source'));
    }
    
    $('.link').on('click', showPic);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been attempting to create a form where a user can simply press
I have been attempting to write a VBA Script that can parse out other
I have been attempting to have a object that I can use across multiple
I'm attempting to build a method call from strings that have been passed into
I have been attemptng to create a DLL with C/C++ that can be accessed
I have been attempting to do some real time video image processing in MonoTouch.
I am new to both Silverlight and WP7. I have been attempting to hotlink
I have been trying to create a new file inside of my application support
I have been attempting to create a simple web service capable of connecting to
I have been attempting to create a timer for my game and I heard

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.