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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:53:44+00:00 2026-05-25T21:53:44+00:00

Recently I needed to attach a large number of a jQuery color picker plugin

  • 0

Recently I needed to attach a large number of a jQuery color picker plugin on a page. With color inputs for borders, shades, gradients, and so on, that quickly became a lot of color pickes. Since the tool was loaded repeatedly for 50+ elements, the page would instantiate 500+ color pickers. Needless to say, the browser suffered big time.

So first, I spend some time trying out different methods for having all the inputs share a single instance of the color picker. It seems to me that that would be the soundest way of doing it. But the project situation didn’t allow me to spend enough time for finding a way of doing that, so I had to come up with an alternative technique.

I did, and I would like to hear what you think about the technique I came up with, and if anyone sees any problems with it?

The idea is, that instead of attaching all the instances of the plugin when the page loads, you wait, and attach just the instances you need – just when you need them.

Here is how I implemented that.

First I had some html with lots and lots of inputs like this one:

<input class="color">

Then, to assign the jQuery color picker plugin to these inputs, I’d normally do something like this:

jQuery(function($) {
    $('input.color').myColorPicker();
});

But that would result in a number of color picker objects being instantiated right away, one for each matched element, each ready to do its stuff when its input is clicked. This normally works fine, but if there are lots of elements, it can make the browser unresponsive.

So instead, here’s how I now attach a color picker to an input on-the-fly if the user actually click on it.

jQuery(function($) {

/* Color pickers*/
$('input.color').live('focus', function(event){

// attach a colorpicker on an as needed basis,
// and only if it is not already attached
if(!$(this).hasClass('haspicker')){
    $(this).myColorPicker().addClass('haspicker');
}

});

When The page loads no color pickers are attached. When the user clicks an input field with the ‘color’ class, it first receives focus, and the picker plugin gets attached, and the element gets an ectra class that is used to prevent subsequent double binding, then the click event fires and triggers the color picker to show up.

It works fine, but I’m not sure if it’s a good practice, or if there could be potential problems with this approach that I haven’t thought of.

So I’d just like to hear what you think?

  • 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-25T21:53:45+00:00Added an answer on May 25, 2026 at 9:53 pm

    Sounds reasonable. Another try would be to have just one picker instance onload, and then attach it to the element in focus (I assume the user never needs two parallel pickers).

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

Sidebar

Related Questions

Recently I needed to generate a huge HTML page containing a report with several
I recently decided that I needed to change from using milliseconds to microseconds for
I've recently needed to write a script that performs an os.fork() to split into
I have jQuery in various files, and recently I have needed to change items
I don't know VBScript, but recently I needed to write a script that had
I recently needed to serialize a datatable to JSON. Where I'm at we're still
While working in a Java app, I recently needed to assemble a comma-delimited list
I'm developing my first java application using Eclipse. I've recently needed to adjust the
I have been recently (and repeatedly) asked by customers about MIPS needed to run
I recently needed to append some data to dynamically created LI elements . In

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.