My JavaScript code needs to get data from a function. The function is returning the data. I know because I see it via a console.log. However, the data it returns is too late for the function that needs it. How do I make it wait for the data? In this case, I need the property defaultColor:
to wait for the function getCol()
.
<script type="text/javascript">
function getCol(col) {
var dcol = '#'+col;
console.log('default color: '+dcol);
return dcol;
}
Coloris({
el: '.coloris',
swatches: [
'#264653',
'#2a9d8f',
'#3665f3',
'#f4a261',
'#e76f51',
'#d62828',
'#023e8a',
'#0077b6',
'#0096c7',
'#00b4d8',
'#48cae4',
'#893783'
],
defaultColor: getCol(),
onChange: function onChange(color) {
console.log(color);
},
inline: true
});
document.addEventListener('coloris:pick', event => {
console.log('New Color', event.detail.color);
});
document.addEventListener('change', event => {
console.log('New Opener', event.detail);
});
</script>