0

I get "Cannot set property 'onchange' of null" console error. When I try to wrap the handler in a window.onload function, it makes the function I am trying to call undefined. I suspect it has something to do with the fact that Spectrumjs "sp-choose" button does not exist until it the color picker is opened.

Here is a link to my Fiddle that best shows the issue.

Scott Floyd
  • 76
  • 1
  • 9
  • The id `sp-chooser` is not generated even after click on color picker. – Suman Bogati Oct 17 '15 at 03:56
  • It's generated when you click on the "choose" button. – Scott Floyd Oct 17 '15 at 05:00
  • I edited the fiddle to show the color picker. But it's still not identifying the 'sp-choose' element. – Scott Floyd Oct 17 '15 at 05:28
  • What about attaching the `onchnage` function after click on "choose" button which means after generated `sp-chooser`? – Suman Bogati Oct 17 '15 at 09:31
  • When I click on `sp-choose` doesn't that fire the call to `fontcolorHandler`? The page is loaded and `sp-choose` does exist. If I run `function fontcolorHandler (id, fn, eventName) { console.log(id); // returns sp-choose` But console reads `TypeError: Cannot set property 'onchange' of null` – Scott Floyd Oct 17 '15 at 18:00
  • Not an answer but a workaround. I ended up reworking the code so it is all triggered only when that button is clicked with this function `$("#custom-3 .sp-choose").on('click', function(obj){...` It works and is doing what I need. – Scott Floyd Oct 18 '15 at 16:54

0 Answers0