My first question: Moving the mouse over the text inside the element (the text is placed in a separate div) works with a very quick repetition of the mouseenter, and it is necessary that it works only once, when entering the square block without reacting to the child elements.
The code was:
$('.square').mouseover(function (e){ var color = colorGenerator(); (this).style.backgroundColor=color; $(this).children('.text').remove(); $('<div>').addClass('text').appendTo(this).text(color); });
I was advised to add this:
$('.square').mouseenter(function (e){ if(!$(e.target).is('.text')){ // тут код, который должен быть выполнен единожды } }
This solved the first problem, but now the color is determined only once and does not change when re-pointing. How to make the color change, but the condition remains? Why is the code in the body of the condition executed only once?