Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTrino Mitra
11,165 PointsUsing JSColor on Handlebars template?
Hello, I am using JSColor (http://jscolor.com/) to show a color picker. In order to make it work all you have to do is put the class "jscolor" on an input or button element and the picker will show up.
However, this only works for elements that are created when the document initially loads.
My problem is that I want the picker to show up on elements that have been created by a handlebars template, which is not working. Does anyone have any experience dealing with issues similar to this?
2 Answers
rydavim
18,814 PointsI haven't used either jscolor or handlebars. However, it sounds like you might be able to just reinitialize jscolor after compiling your handlebars templates?
// Try initializing jscolor after you've handled your templates.
jscolor.init()
That's about as helpful as I can be without seeing your files and doing some more research. If that doesn't work for you, you can post your code here and I can try to fix your specific issue. Good luck!
Riley Manda
1,163 Pointsinnitialize your color as an object,save the color object to console log,then use it later by calling the color object:eg if the color object is called colorOB,then use innit colorOB then where you want to display it with a variable,use for instance var (#yourvariable)colourOb.events.html......then use render function to use the colour
$('#myhtm_id_div .myhtm_id').each(function() { $(this).data('event', { var currColor = "#3c8dbc"; myvariable.css({"background-color": currColor, "border-color": currColor, "color": "#fff"}).addClass("myhtm_id");
Trino Mitra
11,165 PointsTrino Mitra
11,165 PointsI've tried that but it throws an error saying that jscolor.init() is not a function.
Here's the relevant code:
AND HERE'S THE JAVASCRIPT:
rydavim
18,814 Pointsrydavim
18,814 PointsYou could try something a bit more robust at the end of your page:
Unfortunately, without being able to see all of your files and structure, I think I don't have enough experience with handlebars to offer specific advice. Sorry!