I have to write a page where user types some text into a textbox. User clicks the enter button, after this, the text written into the textbox is shown under the textbox. Every letter from the text under textbox should change its color every one second.
I don't know how can I refer to this jQuery function $(function() {} )
because console gives me error that I have to specify the name of the function. I'm just a beginner at programming and I would be very grateful for any kind of help.
var colours = ["#000000", "#FF0000", "#990066", "#FF9966", "#996666", "#00FF00", "#CC9933"],
idx;
$(function() {
var div = $('#arch');
var chars = div.text().split('');
var text = document.getElementById('text').value;
document.getElementById('arch').innerHTML = text;
div.html('');
for(var i = 0; i < chars.length; i++) {
idx = Math.floor(Math.random() * colours.length);
var span = $('<span>' + chars[i] + '</span>').css("color", colours[idx]);
div.append(span);
chars.setInterval(colours, 1000); // change colors of letters every second
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" name="text" id="text">
<button onclick="function()">ENTER</button>
<br /><br />
<div id="arch"></div>