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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:20:31+00:00 2026-05-26T13:20:31+00:00

How could I write javascript that iterates through a table, grabs the class, and

  • 0

How could I write javascript that iterates through a table, grabs the class, and then replaces with an image? So for example I have a table with columns that have numeric classes appended to them:

<td class="images 12-345"></td>
<td class="images 98-763"></td>

These numbers coorelate with image names that I want to load with javascript after the rest of the query is finished processing. So the final product would look like :

<td class="images 12-345"><img src="http://site.com/12-345.jpg"></td>
<td class="images 98-763"><img src="http://site.com/98-763.jpg"></td>

But not until everything is done loading. I would like to just have a placeholder graphic in there that is replaced with the correct image file after everything has processed.

How would I iterate through these rows and then load the appropriate image to each cell? I was thinking first I could use the .images selector to retrieve each unique numeric class name and pass that into a variable. Then with that variable I could append it to the rest of the image path and place it back into its appropriate table cell. I would not want this to begin processing until the rest of the dom had finished loading and the original sql query had completed. Can I please have some advice on what would be the best way to write this. jQuery is an option for me.

  • 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-26T13:20:31+00:00Added an answer on May 26, 2026 at 1:20 pm

    You could do something like this with jQuery:

    $('td.images').each(function() {
        var $td     = $(this);
        var classes = $(this).attr('class').split(/\s+/);
        var num     = $.grep(classes, function(c) { return c.match(/^[\d-]+$/) });
        if(num.length)
            $td.append('<img src="http://site.com/' + num[0] + '.jpg">');
    });
    

    Demo (with just the numbers in the cells): http://jsfiddle.net/ambiguous/vrDvc/1/

    You might need to adjust the $.grep and how you handle the num array to match your real data but the basic technique should work.

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

Sidebar

Related Questions

can you write javascript that produces/writes/etc. functioning javascript? for example, have a link that
I could write myself a helper class that does this when given a functor,
Can non-local-returns be implemented in JavaScript, so that you could write something like: function
I wonder if I could write a program in the C -programming language that
If it said oneword, then I could write #oneword, but what do I write
If you have a C function which returns an integer, you could write a
I want to be able to write javascript that executes on a page that
I have a Javascript question that I am curious about. When using: var test
I currently have a preloading image javascript script: function MM_preloadImages() { var d =
In MVC3 you could write something like this: [Required(ErrorMessage=Please fill some field that I

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.