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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:42:54+00:00 2026-05-24T18:42:54+00:00

I’m working on a product web page. This product page has multiple attributes such

  • 0

I’m working on a product web page. This product page has multiple attributes such as size and color. I’m working on building an image swap script (jQuery) that will swap the main image on the page based on events.

Easy enough and there’s a million tutorials how to do that.

Where this gets less trivial is the attributes. I want to be able to swap images based on the aforementioned attributes selected.

First, the page will display an image that has been set as “default” for a given product.

Second, if someone clicks “size: large”, it will show the image that’s set for size large.

Third, if someone clicks “color: red”, it will pull the “large : red” image and swap it for the main image.

Fourth, if someone now clicks “size : small”, it will fetch the “small : red” image file.

Fifth, if someone now clicks “color : blue”, it will fetch the “small : blue” image file.

You get the idea.

I have a database with the size:color table. The question is, what is the best way to get this data in the HTML page so I can load it into JavaScript?

I want to avoid an AJAX call because of the extra network overhead and the page load will have already accessed the database and gathered all the data, I don’t want to call the database again and have it do all that work a second time.

I could hide the data with CSS (display:none) in the liked elements, but I would be concerned with SEO. There’s a bit of data to hide. There’s thumbnail image URLs, standard size and large size. I certainly wouldn’t want to save it as JSON format like that and just display:none.

I thought maybe saving it in HTML comments and using the jQuery comments() plug-in. I have concerns of speed and feasibility.

Any thoughts on how people best store data in the HTML file to access with JavaScript to build some nice page experience effects?

—- EDIT —-

Having slept on this, I’m thinking that I’m over thinking this whole thing. This whole time I’m trying to figure out how can I add all this product image information into HTML so JavaScript could use it add effects, when all I think I need to do is just have my PHP spit out the image/attribute table as a JavaScript object so I can use it. Instead of trying to figure out some way to re-load it from HTML. Which is just over thinking the whole thing.

  • 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-24T18:42:56+00:00Added an answer on May 24, 2026 at 6:42 pm

    You can spit out the page with a JavaScript block that contains the data for the product in JSON format.

    Alternately you can get clever with class names and put the data in there: red_A12345 would parse out to red image = “A12345.jpg”

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.