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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:43:23+00:00 2026-06-13T00:43:23+00:00

$(#img-switcher).on(switchImageEvent, function(event, triggerID){ $(this).attr(‘src’,triggerID); }); $(#page-container).on(click, img.img-switcher, function() { var newSRC = $(this).attr(‘src’); $(#img-switcher).trigger(switchImageEvent,

  • 0
$("#img-switcher").on("switchImageEvent", function(event, triggerID){
    $(this).attr('src',triggerID);
});
$("#page-container").on("click", "img.img-switcher", function() {
    var newSRC = $(this).attr('src');
    $("#img-switcher").trigger("switchImageEvent", [newSRC]);
});

This code is not working for me with PJAX it seems. If I initially load a page, it selects the elements just fine and makes the change. However, as soon as I go to another page with PJAX, it will no longer select the element for the .on(“click”) action. Am I doing something wrong? I tried adding an alert before var newSRC to see if it was properly selecting the element with .on(), but it isn’t. Any ideas?

  • 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-13T00:43:24+00:00Added an answer on June 13, 2026 at 12:43 am

    Well since there is just this bit of code pulled out of context I would assume you are trying to use on as live instead of using it as delegate.

    With pjax, which uses xhr in order to load elements that have no events attached to them that might be a problem.

    So, my recommendation would be to use parent element which is not reloaded and attach event on it. Like this, with topmost, not reloaded element, instead of body:

    $("body").on("switchImage", "#img-switcher", function(e, src){
      $(this).attr({ 'src': src });
    });
    
    $("body").on("click", "img.img-switcher", function() {
        $("#img-switcher").trigger("switchImage", $(this).attr('src'));
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this event that listens for a click on a img then it
I have an empty img in my page <img ... src=/> When an event
var img = new Image(); img.src = images/myFolder/myImage.png; The above will only load myImage.png.
CSS: img{ max-height:30px; } HTML: <img src=foo.svg /> I am looking for this svg
Heres my Jquery $(.sectiontitle).click(function (e) { $(this).next('div').slideToggle(slow); el = $(this).find(.toggler > a.toggle); currBg =
var img = new Image(); img.src = '/images/backdrop.jpg'; ctx.drawImage(img,0,0); I wanted to load an
jQuery('img').bind('error',function(){ alert('hi'); jQuery(this).hide(); }); I have written this code but non available images are
$(a).each(function() { openFile($(this).attr('href')); } I got this from another question. openFile is a function
I have various img src's like this: http://mydomain.com/wp-content/uploads/2012/10/img-80x93.jpg http://mydomain.com/wp-content/uploads/2012/10/image-80x110.jpg ... I want to change
html img returned from ajax has class of 'tocrop'. Currently I Calling the function

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.