Friday 15 January 2010

javascript - Looking for a way to fire separate events on two different buttons with same class name in spectrumjs -



javascript - Looking for a way to fire separate events on two different buttons with same class name in spectrumjs -

i using spectrumjs , when 1 button clicked invokes code both buttons. if alter class name of 1 of buttons problem solved, color picker dynamically generated , not know how reconfigure code this.

here have:

$(".sp-choose").click(function(){ bgcolor = $("#custom").spectrum("get"); bgcolor = bgcolor.tohexstring(); canvas.backgroundcolor = bgcolor; canvas.setbackgroundimage(); canvas.renderall(); }); $(".sp-choose").click(function() { newcolor = $("#custom2").spectrum("get"); newcolor = newcolor.tohexstring(); canvas.freedrawingbrush.color = newcolor; drawcolor(); canvas.renderall(); });

when alter color of text , click sp-choose button lose original background color, because both of these invoked. not happen after changing color, changing background color or text color changes correctly. it's after first alter of text color lose background.

if there 2 buttons , don't need beautiful solution, may separate these 2 index:

$(".sp-choose").eq(0).click(function(){ bgcolor = $("#custom").spectrum("get"); bgcolor = bgcolor.tohexstring(); canvas.backgroundcolor = bgcolor; canvas.setbackgroundimage(); canvas.renderall(); }); $(".sp-choose").eq(1).click(function() { newcolor = $("#custom2").spectrum("get"); newcolor = newcolor.tohexstring(); canvas.freedrawingbrush.color = newcolor; drawcolor(); canvas.renderall(); });

javascript jquery

No comments:

Post a Comment