You can use the mouseenter event to handle it
$(document).ready(function () {
var $box = $('.box').mousedown(function () {
$(this).toggleClass('highlight');
var flag = $(this).hasClass('highlight')
$box.on('mouseenter.highlight', function () {
$(this).toggleClass('highlight', flag);
});
});
$(document).mouseup(function () {
$box.off('mouseenter.highlight')
})
});
Demo: Fiddle