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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:21:27+00:00 2026-06-18T04:21:27+00:00

I am adding images to my page dynamically with jquery. Basically I am creating

  • 0

I am adding images to my page dynamically with jquery. Basically I am creating “pixel-y / lo-res” versions of the images on the page, and adding the at page load overtop of the originals. Then a typical “fade-out on hover” thing should fade them out on mouseover, showing the orignals.. as if “up – rezing” .. if that makes sense.

So I’ve got the images coming in.. but somehow the hover listener isn’t attaching. At first I tried hover, now I’m on click just because it is easier to troubleshoot. Nothing.

The .on() function should attach itself even to dynamically added items, right? What is going wrong? I’m not getting any errors. It’s just not working.

$.ajax({
        type:"POST",
        url:"js/pixelsandwich/pixelsandwich.php",
        data:{src:src},
        success:function(response){  // if there is already a "lo-rez" image, I get that URL.. if there isn't, one is created and I return that URL
            newImg = $("<img class='crunched'>"); // create the new <img>
            newImg.attr('src', response); // assign the source
            frame = $that.parent(); // grab the containing frame
            frame.append(newImg);  // add the new image.  css:position:absolute and z-index take care of the rest
        }
    });

$(".crunched").on("click", function(){  // << this just isn't attaching at all
     alert("hello");
    $(this).fadeTo('slow',0.5);
});

Cn anyone help?

  • 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-18T04:21:28+00:00Added an answer on June 18, 2026 at 4:21 am

    The .on() function should attach itself even to dynamically added
    items, right?

    Nope, with dynamically created elements you have to bind using .on() to an element that already exists when the code is run. Worst case is usually the body element, but the closer an element you can pick in the DOM the better.

    Assuming that .crunched is the class of your dynamically added elements, try:

    $("body").on("click", ".crunched", function(){  // << this just isn't attaching at all
         alert("hello");
        $(this).fadeTo('slow',0.5);
    });
    

    Per the jQuery docs:

    Event handlers are bound only to the currently selected elements; they
    must exist on the page at the time your code makes the call to .on().
    To ensure the elements are present and can be selected, perform event
    binding inside a document ready handler for elements that are in the
    HTML markup on the page. If new HTML is being injected into the page,
    select the elements and attach event handlers after the new HTML is
    placed into the page.

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

Sidebar

Related Questions

Dynamically adding an image to the page after load then user interaction and am
Hello i have a php file that is dynamically creating images. Basically its adding
I'm adding some <script> tags dynamically to the head element after page load. I
In my app I am dynamically adding images to my view at runtime. I
I've been using JQuery masonry and now I'm adding infinite scroll. There are images
I'm dynamically adding some li s to an unordered list using jQuery. They are
I am getting my List of Images from JSON and adding to page like
I need to dynamically load many (sometimes hundreds) of thumbnail images. For performance reasons
I am having some problems. Basically I am adding images which are loaded via
Okay so here is a random error. I'm dynamically adding images to an html

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.