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

The Archive Base Latest Questions

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

I am creating an interactive colour sampler for a web site, which has 16

  • 0

I am creating an interactive colour sampler for a web site, which has 16 different swatches which can be clicked to show the fullsize preview.

Using jQuery I have a function show_preview(swatch_id) which does all the good visual stuff. However to call that function, I am currently stuck with repeating 16 similar handlers:

<div id="#swatch_clicker_1>
<div id="#swatch_clicker_2>


$("#swatch_clicker_1").click(function() 
{
    show_preview('1');
}   
$("#swatch_clicker_2").click(function() 
{
    show_preview('2');
}
...

I’ve been reading round the subject, including here on Stack Overflow and modified a little code from another answer. So If I were to do something like this, would it still run efficiently (if at-all!)?

<div class="swatch_clicker" id="#swatch_clicker_1>
<div class="swatch_clicker" id="#swatch_clicker_2>


$(".swatch_clicker").click(function(event)
{
    var clicker_id=event.target.id;
    show_preview(clicker_id);
}

Thanks,

Phil

  • 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-26T23:20:01+00:00Added an answer on May 26, 2026 at 11:20 pm

    Well you almost have it right.

    Here’s how I would do it:

    <div class="swatch_clicker" data-preview-number="1"></div>
    <div class="swatch_clicker" data-preview-number="2"></div>
    
    <script>
        $(".swatch_clicker").click(function() {
            show_preview( $(this).data('preview-number') );
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For creating interactive web apps, Silverlight and Jquery (jqueryUI included) are used. Is there
We are creating an ios app, In which we want to use certain interactive
I have a web-site written in ColdFusion that contains both the usual interactive web
I want to creating a graphical editor which a physician can use to create
Creating an XPathDocument with referenced DTD sometimes throws a web exception. Why?
I'm creating interactive charts in java for android environment. Google visualisation API is very
I'm creating an interactive e-book for the iPad. This book will contain multiple pages
I'm creating an interactive app allowing people to customise doors. To allow them to
I have a shell script and this one is interactive and I am creating
I'm creating interactive slideshow control in wpf/c#. I've want to create something similar to

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.