I have some HTML that looks something like this:
<div style="width: 50px; height: 50px; background: #f00" class="t"></div>
<div style="width: 50px; height: 50px; background: #0f0" class="t"></div>
<div style="width: 50px; height: 50px; background: #00f" class="t"></div>
<div style="width: 50px; height: 10px;" id="indicator"></div>
How can I write JavaScript that will make #indicator
's background
color whatever the background of #x
, #y
, or #z
is while a finger is touching the rectangle around x
, y
, and z
?
I can do
$(".t").on('touchstart', function() {
$("#indicator").css('background', $(this).css('backgroundColor'));
});
which does change the color, but can't figure out how to turn the color back to auto
once the finger has left the constrains of the div.t
.
(I know about touchend
, but I want it to revert to the default color as soon as the finger has left the rectangle, not as soon as the finger is picked up.)