Search code examples
javascriptjquerytwitter-bootstrapcolor-picker

Colorpicker mjolnic.com custom element color change


I'm using this plugin:

http://mjolnic.com/bootstrap-colorpicker/

The example below shows how to change the body background color. How can I get it to work to with my custom element/class instead of the body?

My custom element I would like to get to work with:

<div class="strikethrough"></div>

Body, working example as the demo:

  <script>
    $( document ).ready(function() {

    var bodyStyle = $('body')[0].style;

    $('.my-colorpicker').colorpicker().on('changeColor.colorpicker', function(event){
      bodyStyle.backgroundColor = event.color.toHex();
    });

});
</script>

Solution

  • You can select your custom element's style using the class selector like this

    var customeElementStyle = $('.strikethrough')[0].style;