0

I am trying to create a jscolor button using only JavaScript, without starting the page it is in the DOM. I have looked at the examples on the web and the one that most resembles it in HTML is this

<button id="jscolor_prova" data-jscolor="{closeButton:true, closeText:'Change', preset:'large dark', value:'#00CC66'}"></button>

but when I try to create one button with the same features as this it doesn't let me access the data-jscolor attribute from JavaScript. I looked for an API to experiment which this but I can't find any.

Before the last version, the characteristic of jscolor came through the class and it was easier to modify but now they have changed it to this way and I don't know how to achieve that purpose.

The code that I'm trying to replicate is something like this:

function createJscolorButton() {
    var btnDiv = document.getElementById("div_button_jscolor");
    var btn = document.createElement("button");
    btn.id="jscolor_created_js";
    btn.data-jscolor="{closeButton:true, closeText:'Change', preset:'large dark'}";
    btnDiv.appendChild(btn);
}

createJscolorButton();

but when I execute this script I get the following error:

Uncaught SyntaxError: Invalid left-hand side in assignment

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
atp
  • 3
  • 6

0 Answers0