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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:58:44+00:00 2026-06-05T18:58:44+00:00

I have a jQuery function that replaces thumbnails with the main image. This is

  • 0

I have a jQuery function that replaces thumbnails with the main image.
This is the code that I use for replacing the main image:

$(document).ready(function(){
    $(".wheelFinishThumbs a").click(function() {
    var mainImage = $(this).attr("href");
    var mainTemp = mainImage.replace(/-mid/,'');
    var mainTemp = mainTemp.replace(/png/,'jpg');
    $("#main_view img").attr('src', mainImage );
    $("#main_view a").attr('href',mainTemp);
    return false;       
    });

I use a PHP function to download (save) images by changing their header values. This is the HTML code that I use to download images

<a href="#" onclick="window.open('download.php?file=image.jpg','_self', 'download', 'status=0');">Click to download</a> 

but since “image.jpg” has to be my dynamic variable some how I’ve got to call this argument in the jQuery image replacement function and replace “image.jpg” dynamically each time I change the main image. I want to replace image.jpg with var mainImage from my image swapping function.

My jQuery knowledge is really limited, so If somebody can help me to do it, would be great.

  • 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-05T18:58:45+00:00Added an answer on June 5, 2026 at 6:58 pm

    This should work, assuming you are using jQuery 1.7+

    Assuming your a tag markup is like this after you dynamically set the href to new image

    <a href="urltoSomeImage.jpg" id="main_view">Download Image</a>
    

    JavasScript

    $(function(){
      $(document).on("click","#main_view",function(e){
          e.preventDefault();
          var self=$(this);
          alert("replace this with awesome code")
    
          window.open('download.php?file='+self.attr("href")+,'_self', 'download', 'status=0');
      });
    });
    

    Note that this function will work only of a single a element because we are targeting binding the functionality to the element with id main_view. Since ID’s should be unique in the DOM, If you want to have the functionality to many a tags, i would add a common class selector to the a tag like this

    <a class="aDownloadble" href="urltoSomeImage2.jpg" id="main_view">Download Image2</a>
    <a class="aDownloadble" href="urltoSomeImage4.jpg" id="main_view">Download Image4</a>
    

    And Update my script like this

    $(function(){
      $(document).on("click",".aDownloadble",function(e){
          e.preventDefault();
          var self=$(this);
          alert("replace this with awesome code")
    
          window.open('download.php?file='+self.attr("href"),'_self', 'download', 'status=0');
      });
    });
    

    jQuery on is nnot necessary. you can simply use the click event binding directly. But if you are loading the markup of those links via ajax / injecting to the DOM dynamically, you should use on or live.

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

Sidebar

Related Questions

I currently have a jQuery function that replaces an image when clicked. For instance:
Here's the story... I have a jQuery function that does something, this function is
I have this function in jQuery that gets data from a page with POST,
For example sake, I'll use some dummy code. I have some jQuery setup that
I have a bit of JS using JQuery function removeTag() { $('{...}').doSomething(); } $(document).ready(function()
I have the following in my (document).ready function: replace_fav_url(); and the jQuery function: function
Is it a good idea to use a jquery function that replaces each character
i have this jquery function that i want to pass topic parameter to, i
I have this jQuery code that retrieves external content using ajax, without refereshing the
I have a jquery function that should make a calculation based on a textbox

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.