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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:04:38+00:00 2026-05-27T15:04:38+00:00

I am creating some thumbnails dynamically with JQuery, like this (in a loop): var

  • 0

I am creating some thumbnails dynamically with JQuery, like this (in a loop):

var thumb = $('<a class="tinythumb"></a>');
thumb.append('<img src="' + productThumbnailList[i] + '" width="70" height="70" />');
thumbContainer.append(thumb);

Now I’m trying to add some functionality to these via JQuery’s .click(), but I just can’t get it working. I’ve never had trouble trying to do this before, there are no errors and there’s nothing that I can see from my point of view that is incorrect.

I tried this simple .each() to see what would happen. Funnily enough, the rel attribute is being updated, but there’s still no .click() functionality (alert never performed).

$("div#thumbcontainer a").each(function()
{
    $(this).attr("rel", "works");
    $(this).click(function()
    {
        alert('never called');

    });
});

This is the page I’m trying to work with:

http://burwell.businesscatalyst.com/catalogue/containmentscreen/Enviroguard#


Here’s the entire JavaScript which probably has something relevant in it that’s missing above:

// Properties
var thumbContainer = $("div#thumbcontainer");
var str = thumbContainer.html();
var productThumbnailList = str.split(';');

// Clear thumbContainer of junk HTML
thumbContainer.html("");


// Create thumbnails
if(productThumbnailList.length > 1)
{
    for(var i = 0; i<productThumbnailList.length; i++)
    {
        var large = Math.round(i/2) * 2 == i ? false : true;

        // create thumbnail
        if(!large)
        {
            var thumb = $('<a class="tinythumb"></a>');
            thumb.append('<img src="' + productThumbnailList[i] + '" width="70" height="70" />');
            thumbContainer.append(thumb);
        }
    }

    $("div#thumbcontainer a").each(function()
    {
        $(this).attr("rel", "works");
        $(this).click(function()
        {
            alert('never called');

        });

    });
}

Adding an onclick="someFunc()" parameter to the <a> tag makes it call the function fine..

  • 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-05-27T15:04:39+00:00Added an answer on May 27, 2026 at 3:04 pm

    Since you are creating the anchor tag dynamically, use “on” to attach click event handler

    $('#thumbContainer').on("click","a", function(){ 
      alert("will work now"); 
    }); 
    

    http://jsfiddle.net/SUudh/23/

    If you are using older version of jquery, use live() or delegate().

    http://api.jquery.com/live/

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

Sidebar

Related Questions

I am creating some build scripts that interact with Perforce and I would like
I'm creating some scripts to streamline application installations and I need to append to
I'm creating some entities (class) for my project and I want to set a
After reading some posts like this one: Choose File Dialog It appears that Android
I am working on creating some grails domain objects dynamically and then adding them
Creating some simple html pages specific for the iphone, and would like to use
I'm creating some application that plays sounds like piano, drums etc. I have a
i am creating some custom exceptions as follows lib/exceptions.rb module Exceptions class MemberOverFlow <
I'm creating some checkbox elements on the fly with jQuery and appending them to
I am creating some custom selectboxes with jQuery so I can style them exactly

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.