1

I'm trying to clear the WordPress colorpicker but seems it doesn't work. This is what I'Ve tried:

$('#element').wpColorPicker('clear');
//error: Uncaught Error: no such method 'clear' for wpColorPicker widget instance
$('#element').wpColorPicker('color', '#');
//no output/change  
$('#element').wpColorPicker('color', '');
//no output/change

Of course there's no method mentioned in the documentation but there's a options for a callback method so it's maybe possible via some "hacking"?

  • How about this documentation. make.wordpress.org/core/2012/11/30/new-color-picker-in-wp-3-5 – matthew Sep 4 '15 at 16:46
  • not really helpful in this case – Xaver Sep 4 '15 at 17:03
  • Do you see any errors in your console? – czerspalace Sep 4 '15 at 17:32
  • not really, I've updated my question – Xaver Sep 4 '15 at 17:36
  • Please add more code. How do you trigger the wpColorPicker? On document_ready handler? Additionally please ensure if jquery enqueued before colorpicker scripts and both libs loads well. – Ignat B. Sep 4 '15 at 20:53
0

This is hacky but gets the job done.

$('#element .wp-picker-clear').trigger('click');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.