Reputation: 474
Using jQuery (3.5.1) In the below example I have difficulties with having the script being stable when mouse leaves the TR
, the issue is that the hovering text and icon animation sometimes stays in the TD
and are not reset to the $originalText
.
Initiallly I made the jQuery global using classes in the hover instead of ID, and I had global class for the .html
, and I have tried building it with mouseout
and mouseleave
but these efforts where more unstable than having a script per TR
- yes, I know it ain´t pretty .. unfortunately, as you can see in the below code and snippet it does not work great, it initially does reset the hovering text to $originalText
, but if you move over it multiple times or fast it will not reset the state back to original.
Can anyone see what the issue is, and how I can fix it?
My code
var id = 315
$('#tr_user_tasksIT' + id).hover(
function() {
$originalText = $('.TaskTextSpanIT' + id).html();
$('.TaskTextSpanIT' + id).html('<font class="text-success">CLICK AND GO TO TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-success"></i>');
},
function() {
$('.TaskTextSpanIT' + id).html($originalText);
}
);
$('#tr_user_tasksIT_NotDone' + id).hover(
function() {
$originalText = $('.TaskTextSpanIT' + id).html();
$('.TaskTextSpanIT' + id).html('<font class="text-danger">CLICK AND SOLVE TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-danger"></i>');
},
function() {
$('.TaskTextSpanIT' + id).html($originalText);
}
);
$('#tr_user_tasksCFO' + id).hover(
function() {
$originalText = $('.TaskTextSpanCFO' + id).html();
$('.TaskTextSpanCFO' + id).html('<font class="text-success">CLICK AND GO TO TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-success"></i>');
},
function() {
$('.TaskTextSpanCFO' + id).html($originalText);
}
);
$('#tr_user_tasksCFO_NotDone' + id).hover(
function() {
$originalText = $('.TaskTextSpanCFO' + id).html();
$('.TaskTextSpanCFO' + id).html('<font class="text-danger">CLICK AND SOLVE TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-danger"></i>');
},
function() {
$('.TaskTextSpanCFO' + id).html($originalText);
}
);
$('#tr_user_tasksEconomy' + id).hover(
function() {
$originalText = $('.TaskTextSpanEconomy' + id).html();
$('.TaskTextSpanEconomy' + id).html('<font class="text-success">CLICK AND GO TO TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-success"></i>');
},
function() {
$('.TaskTextSpanEconomy' + id).html($originalText);
}
);
$('#tr_user_tasksEconomy_NotDone' + id).hover(
function() {
$originalText = $('.TaskTextSpanEconomy' + id).html();
$('.TaskTextSpanEconomy' + id).html('<font class="text-danger">CLICK AND SOLVE TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-danger"></i>');
},
function() {
$('.TaskTextSpanEconomy' + id).html($originalText);
}
);
$('#tr_user_tasksAcademy' + id).hover(
function() {
$originalText = $('.TaskTextSpanAcademy' + id).html();
$('.TaskTextSpanAcademy' + id).html('<font class="text-success">CLICK AND GO TO TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-success"></i>');
},
function() {
$('.TaskTextSpanAcademy' + id).html($originalText);
}
);
$('#tr_user_tasksAcademy_NotDone' + id).hover(
function() {
$originalText = $('.TaskTextSpanAcademy' + id).html();
$('.TaskTextSpanAcademy' + id).html('<font class="text-danger">CLICK AND SOLVE TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-danger"></i>');
},
function() {
$('.TaskTextSpanAcademy' + id).html($originalText);
}
);
$('#tr_user_tasksPublicator' + id).hover(
function() {
$originalText = $('.TaskTextSpanPublicator' + id).html();
$('.TaskTextSpanPublicator' + id).html('<font class="text-success">CLICK AND GO TO TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-success"></i>');
},
function() {
$('.TaskTextSpanPublicator' + id).html($originalText);
}
);
$('#tr_user_tasksPublicator_NotDone' + id).hover(
function() {
$originalText = $('.TaskTextSpanPublicator' + id).html();
$('.TaskTextSpanPublicator' + id).html('<font class="text-danger">CLICK AND SOLVE TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-danger"></i>');
},
function() {
$('.TaskTextSpanPublicator' + id).html($originalText);
}
);
$('#tr_user_tasksBogportal' + id).hover(
function() {
$originalText = $('.TaskTextSpanBogportal' + id).html();
$('.TaskTextSpanBogportal' + id).html('<font class="text-success">CLICK AND GO TO TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-success"></i>');
},
function() {
$('.TaskTextSpanBogportal' + id).html($originalText);
}
);
$('#tr_user_tasksBogportal_NotDone' + id).hover(
function() {
$originalText = $('.TaskTextSpanBogportal' + id).html();
$('.TaskTextSpanBogportal' + id).html('<font class="text-danger">CLICK AND SOLVE TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-danger"></i>');
},
function() {
$('.TaskTextSpanBogportal' + id).html($originalText);
}
);
$('#tr_user_tasksWelcomePackage' + id).hover(
function() {
$originalText = $('.TaskTextSpanWelcomePackage' + id).html();
$('.TaskTextSpanWelcomePackage' + id).html('<font class="text-success">CLICK AND GO TO TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-success"></i>');
},
function() {
$('.TaskTextSpanWelcomePackage' + id).html($originalText);
}
);
$('#tr_user_tasksWelcomePackage_NotDone' + id).hover(
function() {
$originalText = $('.TaskTextSpanWelcomePackage' + id).html();
$('.TaskTextSpanWelcomePackage' + id).html('<font class="text-danger">CLICK AND SOLVE TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-danger"></i>');
},
function() {
$('.TaskTextSpanWelcomePackage' + id).html($originalText);
}
);
$('#tr_user_tasksKeyCardDone' + id).hover(
function() {
$originalText = $('.TaskTextSpanKeyCardDone' + id).html();
$('.TaskTextSpanKeyCardDone' + id).html('<font class="text-success">CLICK AND GO TO TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-success"></i>');
},
function() {
$('.TaskTextSpanKeyCardDone' + id).html($originalText);
}
);
$('#tr_user_tasksKeyCardDone_NotDone' + id).hover(
function() {
$originalText = $('.TaskTextSpanKeyCardDone' + id).html();
$('.TaskTextSpanKeyCardDone' + id).html('<font class="text-danger">CLICK AND SOLVE TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-danger"></i>');
},
function() {
$('.TaskTextSpanKeyCardDone' + id).html($originalText);
}
);
$('#tr_user_tasksPortraitDone' + id).hover(
function() {
$originalText = $('.TaskTextSpanPortraitDone' + id).html();
$('.TaskTextSpanPortraitDone' + id).html('<font class="text-success">CLICK AND GO TO TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-success"></i>');
},
function() {
$('.TaskTextSpanPortraitDone' + id).html($originalText);
}
);
$('#tr_user_tasksPortraitDone_NotDone' + id).hover(
function() {
$originalText = $('.TaskTextSpanPortraitDone' + id).html();
$('.TaskTextSpanPortraitDone' + id).html('<font class="text-danger">CLICK AND SOLVE TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-danger"></i>');
},
function() {
$('.TaskTextSpanPortraitDone' + id).html($originalText);
}
);
$('#tr_user_tasksWhoIsWhoDone' + id).hover(
function() {
$originalText = $('.TaskTextSpanWhoIsWhoDone' + id).html();
$('.TaskTextSpanWhoIsWhoDone' + id).html('<font class="text-success">CLICK AND GO TO TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-success"></i>');
},
function() {
$('.TaskTextSpanWhoIsWhoDone' + id).html($originalText);
}
);
$('#tr_user_tasksWhoIsWhoDone_NotDone' + id).hover(
function() {
$originalText = $('.TaskTextSpanWhoIsWhoDone' + id).html();
$('.TaskTextSpanWhoIsWhoDone' + id).html('<font class="text-danger">CLICK AND SOLVE TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-danger"></i>');
},
function() {
$('.TaskTextSpanWhoIsWhoDone' + id).html($originalText);
}
);
$('#tr_user_tasksAGR' + id).hover(
function() {
$originalText = $('.TaskTextSpanAGR' + id).html();
$('.TaskTextSpanAGR' + id).html('<font class="text-success">CLICK AND GO TO TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-success"></i>');
},
function() {
$('.TaskTextSpanAGR' + id).html($originalText);
}
);
$('#tr_user_tasksAGR_NotDone' + id).hover(
function() {
$originalText = $('.TaskTextSpanAGR' + id).html();
$('.TaskTextSpanWhoIsAGR' + id).html('<font class="text-danger">CLICK AND SOLVE TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-danger"></i>');
},
function() {
$('.TaskTextSpanAGR' + id).html($originalText);
}
);
$('#tr_user_taskseTrack' + id).hover(
function() {
$originalText = $('.TaskTextSpaneTrack' + id).html();
$('.TaskTextSpaneTrack' + id).html('<font class="text-success">CLICK AND GO TO TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-success"></i>');
},
function() {
$('.TaskTextSpaneTrack' + id).html($originalText);
}
);
$('#tr_user_taskseTrack_NotDone' + id).hover(
function() {
$originalText = $('.TaskTextSpaneTrack' + id).html();
$('.TaskTextSpanWhoIseTrack' + id).html('<font class="text-danger">CLICK AND SOLVE TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-danger"></i>');
},
function() {
$('.TaskTextSpaneTrack' + id).html($originalText);
}
);
$('#tr_user_tasksPhone' + id).hover(
function() {
$originalText = $('.TaskTextSpanPhone' + id).html();
$('.TaskTextSpanPhone' + id).html('<font class="text-success">CLICK AND GO TO TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-success"></i>');
},
function() {
$('.TaskTextSpanPhone' + id).html($originalText);
}
);
$('#tr_user_tasksPhone_NotDone' + id).hover(
function() {
$originalText = $('.TaskTextSpanPhone' + id).html();
$('.TaskTextSpanPhone' + id).html('<font class="text-danger">CLICK AND SOLVE TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-danger"></i>');
},
function() {
$('.TaskTextSpanPhone' + id).html($originalText);
}
);
.tr_user_tasks:hover {
background: #e9ecef;
}
.hand_user_tasks {
cursor: pointer;
}
.arrowbounce {
position: absolute;
width: 50px;
right: 10px;
margin: 5px;
animation: bounce 1s infinite alternate;
-webkit-animation: bounce 1s infinite alternate;
}
@keyframes bounce {
from {
transform: translateX(0px);
}
to {
transform: translateX(-15px);
}
}
@-webkit-keyframes bounce {
from {
transform: translateX(0px);
}
to {
transform: translateX(-15px);
}
}
*,
*:before,
*:after {
box-sizing: border-box;
}
.hourglass-small {
font-size: .2em;
}
.hourglass {
width: 3.5em;
height: 5em;
border-style: solid;
border-width: 2.5em 1.2em;
border-color: #ffc107 transparent;
border-radius: 10%;
position: relative;
animation: spin 5s linear infinite;
}
.hourglass:before {
content: "";
width: 2.5em;
height: 4.5em;
border-style: solid;
border-width: 2.25em 1.1em;
border-color: white transparent transparent;
border-radius: 10%;
position: absolute;
top: -2.25em;
left: -.7em;
animation: slideOut 5s linear infinite;
box-sizing: border-box;
}
.hourglass:after {
content: "";
width: 2.5em;
height: 4.5em;
border-style: solid;
border-width: 0em 1.1em;
border-color: transparent transparent white;
border-radius: 10%;
position: absolute;
top: -2.25em;
left: -.7em;
animation: slideIn 5s linear infinite;
color: #ffc107;
}
@keyframes spin {
0% {
transform: rotation(0deg);
}
90% {
transform: rotate(0deg);
}
100% {
transform: rotate(180deg);
}
}
@keyframes slideOut {
0% {
top: -2.25em;
width: 2.5;
border-width: 2.25em 1.1em;
}
90% {
top: 0em;
width: 0;
border-width: 0em 0em;
left: .55em;
}
100% {
top: 0em;
width: 0;
border-width: 0em 0em;
left: .55em;
}
}
@keyframes slideIn {
0% {
border-width: 0em 1.1em;
}
90% {
border-width: 2.25em 1.1em;
}
100% {
border-width: 2.25em 1.1em;
}
}
.fa-beat {
animation: fa-beat 5s ease infinite;
}
@keyframes fa-beat {
0% {
transform: scale(1);
}
5% {
transform: scale(1.5);
}
20% {
transform: scale(1);
}
30% {
transform: scale(1);
}
35% {
transform: scale(1.5);
}
50% {
transform: scale(1);
}
55% {
transform: scale(1.5);
}
70% {
transform: scale(1);
}
}
.truncate {
width: 250px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<script src="https://kit.fontawesome.com/e3a6e5f796.js" crossorigin="anonymous"></script>
<table>
<tr style="border: 0px solid #FFFFFF;" class="tr-hover" data-href="flow.asp?ShowPagePart=FlowNotDone&GetSpecificUserOnFlow=yes&UserIDOnFlow=315">
<td>
<div class="blob red" id="StatusToolTipJoinLess50Percent">
<center>
<font style="color: #FFFFFF;"><b>T</b></font>
</center>
</div>
</td>
<td>Some Name</td>
<td>28-05-2021</td>
<td>40,00 %</td>
<tr>
<tr style="border: 0px solid #FFFFFF;">
<td colspan="4">
<div role="row" class="progress shadow mb-2 bg-gray" aria-colspan="4">
<div role="cell" aria-colspan="4" class="progress-bar
bg-danger
" role="progressbar" style="width: 40%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">40,00%</div>
</div>
<table style="width: 100%;" cellpadding="1" colspan="1">
<tr id="tr_user_tasksIT_NotDone315" class="tr_user_tasks hand_user_tasks" onclick="window.location='confirm_tasks_solved.asp?RoleType=IT2&id=315';">
<td align="center" style="width: 30px;"><i class="fas fa-exclamation-triangle text-danger fa-beat"></i></td>
<td>
<div class="TaskTextSpanIT315" style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep1 - Info received - awaits you</b></font>
</div>
</td>
</tr>
<tr id="tr_user_tasksCFO315" class="tr_user_tasks hand_user_tasks" onclick="window.location='confirm_tasks_solved.asp?RoleType=cfo&id=315';">
<td align="center" style="width: 30px;"><i class="fas fa-check text-success"></i></td>
<td>
<div class="TaskTextSpanCFO315" style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep2 - Finished d. 05-05-2021</b></font>
<DIV>
</td>
</tr>
<tr id="tr_user_tasksEconomy_NotDone315" class="tr_user_tasks hand_user_tasks" onclick="window.location='sallary_info.asp?RoleType=economy&id=315';">
<td align="center" style="width: 30px;"><i class="fas fa-exclamation-triangle text-danger fa-beat"></i></td>
<td>
<div class="TaskTextSpanEconomy315" style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep 3 - Adviced 05-05-2021 - awaits you</b></font>
</div>
</td>
</tr>
<tr id="tr_user_tasksAcademy315" class="tr_user_tasks">
<td align="center" style="width: 30px;">
<div class="hourglass hourglass-small"></div>
</td>
<td>
<div style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep3 - Not yet Adviced - awaits Some Person</b></font>
</div>
</td>
</tr>
<tr class="tr_user_tasks">
<td align="center" style="width: 30px;">
<div class="hourglass hourglass-small"></div>
</td>
<td>
<div style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep4 - Not yet Adviced - awaits Some Person</b></font>
</div>
</td>
</tr>
<tr class="tr_user_tasks">
<td align="center" style="width: 30px;">
<div class="hourglass hourglass-small"></div>
</td>
<td>
<div style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep5 - Not yet Adviced - awaits Some Person</b></font>
</div>
</td>
</tr>
<tr id="tr_user_tasksWelcomePackage_NotDone315" class="tr_user_tasks hand_user_tasks" onclick="window.location='confirm_tasks_solved.asp?RoleType=WelcomePackage&id=315';">
<td align="center" style="width: 30px;"><i class="fas fa-exclamation-triangle text-danger fa-beat"></i></td>
<td>
<div class="TaskTextSpanWelcomePackage315" style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep6 - Adviced 05-05-2021 - awaits you</b></font>
</div>
</td>
</tr>
<tr id="tr_user_tasksKeyCardDone315" class="tr_user_tasks hand_user_tasks" onclick="window.location='confirm_tasks_solved.asp?RoleType=AccessKey&id=315';">
<td align="center" style="width: 30px;"><i class="fas fa-check text-success"></i></td>
<td>
<div class="TaskTextSpanKeyCardDone315" style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep7 - Finished d. 05-05-2021</b></font>
</div>
</td>
</tr>
<tr id="tr_user_tasksPortraitDone_NotDone315" class="tr_user_tasks hand_user_tasks" onclick="window.location='confirm_tasks_solved.asp?RoleType=Portrait&id=315';">
<td align="center" style="width: 30px;"><i class="fas fa-exclamation-triangle text-danger fa-beat"></i></td>
<td>
<div class="TaskTextSpanPortraitDone315" style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep8 - Adviced 05-05-2021 - awaits you</b></font>
</div>
</td>
</tr>
<tr class="tr_user_tasks">
<td align="center" style="width: 30px;">
<div class="hourglass hourglass-small"></div>
</td>
<td>
<div style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep9 - Not yet Adviced - awaits Some Person</b></font>
</div>
</td>
</tr>
<tr class="tr_user_tasks">
<td align="center" style="width: 30px;">
<div class="hourglass hourglass-small"></div>
</td>
<td>
<div style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep10 - Not yet Adviced - awaits Some Person</b></font>
</div>
</td>
</tr>
<tr class="tr_user_tasks">
<td align="center" style="width: 30px;">
<div class="hourglass hourglass-small"></div>
</td>
<td>
<div style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep11 - Not yet Adviced - awaits Some Person</b></font>
</div>
</td>
</tr>
<tr id="tr_user_tasksPhone_NotDone315" class="tr_user_tasks hand_user_tasks" onclick="window.location='confirm_tasks_solved.asp?RoleType=Phone&id=315';">
<td align="center" style="width: 30px;"><i class="fas fa-exclamation-triangle text-danger fa-beat"></i></td>
<td>
<div class="TaskTextSpanPhone315" style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep12 - Adviced 05-05-2021 - awaits you</b></font>
</div>
</td>
</tr>
</table>
</td>
<tr>
</table>
UPDATE : Current jQuery:
$(document).ready(function(){
var id = <%=objFlowNotDoneMainPage("ID")%>
$( '#tr_user_tasksIT' + id ).hover(
function() {
$originalText['.TaskTextSpanIT' + id] = $( '.TaskTextSpanIT' + id ).html();
$( '.TaskTextSpanIT' + id ).html('<font class="text-success">KLIK FOR AT GÅ TIL DEN LØSTE OPGAVE</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-success"></i>');
}, function() {
$( '.TaskTextSpanIT' + id ).html( $originalText['.TaskTextSpanIT' + id] );
}
);
$( '#tr_user_tasksIT_NotDone' + id ).hover(
function() {
$originalText['.TaskTextSpanIT' + id] = $( '.TaskTextSpanIT' + id ).html();
$( '.TaskTextSpanIT' + id ).html('<font class="text-danger">GÅ TIL OPGAVEN OG MARKERE DEN SOM LØST</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-danger"></i>');
}, function() {
$( '.TaskTextSpanIT' + id ).html( $originalText['.TaskTextSpanIT' + id] );
}
);
});
I i.e tried toadd the check like this:
}, function() {
if((originalText['.TaskTextSpanIT' + id] || "") === "") originalText['.TaskTextSpanIT' + id] = newText
$( '.TaskTextSpanIT' + id ).html( newText );
}
Which does not work
Upvotes: 0
Views: 71
Reputation: 28611
The original issue was that $originalText
was a single variable that changed for each row, but the order of events can't be guaranteed.
So one element's hover-on will set a new value for originalText before the next element's hover-off has a chance to reset the value.
One option is to store the originalText as an array, based on the element's ID.
There are two parts:
var originalText = [];
this was previously implied (created automatically) but is required for an array.
originalText['.TaskTextSpanIT' + id] = $('.TaskTextSpanIT' + id).html();
This can be extended to reduce the need to re-call .html()
(and potentially get the updated html instead of the original html)
originalText['.TaskTextSpanIT' + id] = originalText['.TaskTextSpanIT' + id] || $('.TaskTextSpanIT' + id).html();
(note, newer versions of javascript also have ||=
and ??=
which can be used instead of x=x||y
)
Updating your snippet, I also now see that you have two elements hover, which both change the same element, so I've combined these to a single event handler.
A better option might be to include both bits of html in the code and simply .toggle()
them.
var id = 315
var originalText = [];
$('#tr_user_tasksIT' + id + ',#tr_user_tasksIT_NotDone' + id).hover(
function() {
originalText['.TaskTextSpanIT' + id] = originalText['.TaskTextSpanIT' + id] || $('.TaskTextSpanIT' + id).html();
$('.TaskTextSpanIT' + id).html('<font class="text-success">CLICK AND GO TO TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-success"></i>');
},
function() {
$('.TaskTextSpanIT' + id).html(originalText['.TaskTextSpanIT' + id]);
}
);
$('#tr_user_tasksCFO' + id + ',#tr_user_tasksCFO_NotDone' + id).hover(
function() {
originalText['.TaskTextSpanCFO' + id] = originalText['.TaskTextSpanCFO' + id] || $('.TaskTextSpanCFO' + id).html();
$('.TaskTextSpanCFO' + id).html('<font class="text-success">CLICK AND GO TO TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-success"></i>');
},
function() {
$('.TaskTextSpanCFO' + id).html(originalText['.TaskTextSpanCFO' + id]);
}
);
$('#tr_user_tasksEconomy' + id + ',#tr_user_tasksEconomy_NotDone' + id).hover(
function() {
originalText['.TaskTextSpanEconomy' + id] = originalText['.TaskTextSpanEconomy' + id] || $('.TaskTextSpanEconomy' + id).html();
$('.TaskTextSpanEconomy' + id).html('<font class="text-success">CLICK AND GO TO TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-success"></i>');
},
function() {
$('.TaskTextSpanEconomy' + id).html(originalText['.TaskTextSpanEconomy' + id]);
}
);
.tr_user_tasks:hover {
background: #e9ecef;
}
.hand_user_tasks {
cursor: pointer;
}
.arrowbounce {
position: absolute;
width: 50px;
right: 10px;
margin: 5px;
animation: bounce 1s infinite alternate;
-webkit-animation: bounce 1s infinite alternate;
}
@keyframes bounce {
from {
transform: translateX(0px);
}
to {
transform: translateX(-15px);
}
}
@-webkit-keyframes bounce {
from {
transform: translateX(0px);
}
to {
transform: translateX(-15px);
}
}
*,
*:before,
*:after {
box-sizing: border-box;
}
.hourglass-small {
font-size: .2em;
}
.hourglass {
width: 3.5em;
height: 5em;
border-style: solid;
border-width: 2.5em 1.2em;
border-color: #ffc107 transparent;
border-radius: 10%;
position: relative;
animation: spin 5s linear infinite;
}
.hourglass:before {
content: "";
width: 2.5em;
height: 4.5em;
border-style: solid;
border-width: 2.25em 1.1em;
border-color: white transparent transparent;
border-radius: 10%;
position: absolute;
top: -2.25em;
left: -.7em;
animation: slideOut 5s linear infinite;
box-sizing: border-box;
}
.hourglass:after {
content: "";
width: 2.5em;
height: 4.5em;
border-style: solid;
border-width: 0em 1.1em;
border-color: transparent transparent white;
border-radius: 10%;
position: absolute;
top: -2.25em;
left: -.7em;
animation: slideIn 5s linear infinite;
color: #ffc107;
}
@keyframes spin {
0% {
transform: rotation(0deg);
}
90% {
transform: rotate(0deg);
}
100% {
transform: rotate(180deg);
}
}
@keyframes slideOut {
0% {
top: -2.25em;
width: 2.5;
border-width: 2.25em 1.1em;
}
90% {
top: 0em;
width: 0;
border-width: 0em 0em;
left: .55em;
}
100% {
top: 0em;
width: 0;
border-width: 0em 0em;
left: .55em;
}
}
@keyframes slideIn {
0% {
border-width: 0em 1.1em;
}
90% {
border-width: 2.25em 1.1em;
}
100% {
border-width: 2.25em 1.1em;
}
}
.fa-beat {
animation: fa-beat 5s ease infinite;
}
@keyframes fa-beat {
0% {
transform: scale(1);
}
5% {
transform: scale(1.5);
}
20% {
transform: scale(1);
}
30% {
transform: scale(1);
}
35% {
transform: scale(1.5);
}
50% {
transform: scale(1);
}
55% {
transform: scale(1.5);
}
70% {
transform: scale(1);
}
}
.truncate {
width: 250px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<script src="https://kit.fontawesome.com/e3a6e5f796.js" crossorigin="anonymous"></script>
<table>
<tr style="border: 0px solid #FFFFFF;" class="tr-hover" data-href="flow.asp?ShowPagePart=FlowNotDone&GetSpecificUserOnFlow=yes&UserIDOnFlow=315">
<td>
<div class="blob red" id="StatusToolTipJoinLess50Percent">
<center>
<font style="color: #FFFFFF;"><b>T</b></font>
</center>
</div>
</td>
<td>Some Name</td>
<td>28-05-2021</td>
<td>40,00 %</td>
<tr>
<tr style="border: 0px solid #FFFFFF;">
<td colspan="4">
<div role="row" class="progress shadow mb-2 bg-gray" aria-colspan="4">
<div role="cell" aria-colspan="4" class="progress-bar
bg-danger
" role="progressbar" style="width: 40%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">40,00%</div>
</div>
<table style="width: 100%;" cellpadding="1" colspan="1">
<tr id="tr_user_tasksIT_NotDone315" class="tr_user_tasks hand_user_tasks" onclick="window.location='confirm_tasks_solved.asp?RoleType=IT2&id=315';">
<td align="center" style="width: 30px;"><i class="fas fa-exclamation-triangle text-danger fa-beat"></i></td>
<td>
<div class="TaskTextSpanIT315" style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep1 - Info received - awaits you</b></font>
</div>
</td>
</tr>
<tr id="tr_user_tasksCFO315" class="tr_user_tasks hand_user_tasks" onclick="window.location='confirm_tasks_solved.asp?RoleType=cfo&id=315';">
<td align="center" style="width: 30px;"><i class="fas fa-check text-success"></i></td>
<td>
<div class="TaskTextSpanCFO315" style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep2 - Finished d. 05-05-2021</b></font>
<DIV>
</td>
</tr>
<tr id="tr_user_tasksEconomy_NotDone315" class="tr_user_tasks hand_user_tasks" onclick="window.location='sallary_info.asp?RoleType=economy&id=315';">
<td align="center" style="width: 30px;"><i class="fas fa-exclamation-triangle text-danger fa-beat"></i></td>
<td>
<div class="TaskTextSpanEconomy315" style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep 3 - Adviced 05-05-2021 - awaits you</b></font>
</div>
</td>
</tr>
<tr id="tr_user_tasksAcademy315" class="tr_user_tasks">
<td align="center" style="width: 30px;">
<div class="hourglass hourglass-small"></div>
</td>
<td>
<div style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep3 - Not yet Adviced - awaits Some Person</b></font>
</div>
</td>
</tr>
<tr class="tr_user_tasks">
<td align="center" style="width: 30px;">
<div class="hourglass hourglass-small"></div>
</td>
<td>
<div style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep4 - Not yet Adviced - awaits Some Person</b></font>
</div>
</td>
</tr>
<tr class="tr_user_tasks">
<td align="center" style="width: 30px;">
<div class="hourglass hourglass-small"></div>
</td>
<td>
<div style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep5 - Not yet Adviced - awaits Some Person</b></font>
</div>
</td>
</tr>
<tr id="tr_user_tasksWelcomePackage_NotDone315" class="tr_user_tasks hand_user_tasks" onclick="window.location='confirm_tasks_solved.asp?RoleType=WelcomePackage&id=315';">
<td align="center" style="width: 30px;"><i class="fas fa-exclamation-triangle text-danger fa-beat"></i></td>
<td>
<div class="TaskTextSpanWelcomePackage315" style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep6 - Adviced 05-05-2021 - awaits you</b></font>
</div>
</td>
</tr>
<tr id="tr_user_tasksKeyCardDone315" class="tr_user_tasks hand_user_tasks" onclick="window.location='confirm_tasks_solved.asp?RoleType=AccessKey&id=315';">
<td align="center" style="width: 30px;"><i class="fas fa-check text-success"></i></td>
<td>
<div class="TaskTextSpanKeyCardDone315" style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep7 - Finished d. 05-05-2021</b></font>
</div>
</td>
</tr>
<tr id="tr_user_tasksPortraitDone_NotDone315" class="tr_user_tasks hand_user_tasks" onclick="window.location='confirm_tasks_solved.asp?RoleType=Portrait&id=315';">
<td align="center" style="width: 30px;"><i class="fas fa-exclamation-triangle text-danger fa-beat"></i></td>
<td>
<div class="TaskTextSpanPortraitDone315" style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep8 - Adviced 05-05-2021 - awaits you</b></font>
</div>
</td>
</tr>
<tr class="tr_user_tasks">
<td align="center" style="width: 30px;">
<div class="hourglass hourglass-small"></div>
</td>
<td>
<div style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep9 - Not yet Adviced - awaits Some Person</b></font>
</div>
</td>
</tr>
<tr class="tr_user_tasks">
<td align="center" style="width: 30px;">
<div class="hourglass hourglass-small"></div>
</td>
<td>
<div style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep10 - Not yet Adviced - awaits Some Person</b></font>
</div>
</td>
</tr>
<tr class="tr_user_tasks">
<td align="center" style="width: 30px;">
<div class="hourglass hourglass-small"></div>
</td>
<td>
<div style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep11 - Not yet Adviced - awaits Some Person</b></font>
</div>
</td>
</tr>
<tr id="tr_user_tasksPhone_NotDone315" class="tr_user_tasks hand_user_tasks" onclick="window.location='confirm_tasks_solved.asp?RoleType=Phone&id=315';">
<td align="center" style="width: 30px;"><i class="fas fa-exclamation-triangle text-danger fa-beat"></i></td>
<td>
<div class="TaskTextSpanPhone315" style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep12 - Adviced 05-05-2021 - awaits you</b></font>
</div>
</td>
</tr>
</table>
</td>
<tr>
</table>
You can also substantially reduce the amount of code you need (but I didn't check every bit of text was the same, so shows an idea only)
var id = 315
var originalText = [];
$(".tr_user_tasks").hover(
function() {
originalText[this.id] = originalText[this.id] || $(this).find("td:eq(1)>div").html();
// if this had a different class, it would be easier to find, but class has an id munged
// :eq() is deprecated, so add a class to the 2nd td
$(this).find("td:eq(1)>div").html('<font class="text-success">CLICK AND GO TO TASK</font> <i class="fas fa-arrow-alt-circle-left fa-lg arrowbounce text-success"></i>')
},
function() {
$(this).find("td:eq(1)>div").html(originalText[this.id]);
});
.tr_user_tasks:hover {
background: #e9ecef;
}
.hand_user_tasks {
cursor: pointer;
}
.arrowbounce {
position: absolute;
width: 50px;
right: 10px;
margin: 5px;
animation: bounce 1s infinite alternate;
-webkit-animation: bounce 1s infinite alternate;
}
@keyframes bounce {
from {
transform: translateX(0px);
}
to {
transform: translateX(-15px);
}
}
@-webkit-keyframes bounce {
from {
transform: translateX(0px);
}
to {
transform: translateX(-15px);
}
}
*,
*:before,
*:after {
box-sizing: border-box;
}
.hourglass-small {
font-size: .2em;
}
.hourglass {
width: 3.5em;
height: 5em;
border-style: solid;
border-width: 2.5em 1.2em;
border-color: #ffc107 transparent;
border-radius: 10%;
position: relative;
animation: spin 5s linear infinite;
}
.hourglass:before {
content: "";
width: 2.5em;
height: 4.5em;
border-style: solid;
border-width: 2.25em 1.1em;
border-color: white transparent transparent;
border-radius: 10%;
position: absolute;
top: -2.25em;
left: -.7em;
animation: slideOut 5s linear infinite;
box-sizing: border-box;
}
.hourglass:after {
content: "";
width: 2.5em;
height: 4.5em;
border-style: solid;
border-width: 0em 1.1em;
border-color: transparent transparent white;
border-radius: 10%;
position: absolute;
top: -2.25em;
left: -.7em;
animation: slideIn 5s linear infinite;
color: #ffc107;
}
@keyframes spin {
0% {
transform: rotation(0deg);
}
90% {
transform: rotate(0deg);
}
100% {
transform: rotate(180deg);
}
}
@keyframes slideOut {
0% {
top: -2.25em;
width: 2.5;
border-width: 2.25em 1.1em;
}
90% {
top: 0em;
width: 0;
border-width: 0em 0em;
left: .55em;
}
100% {
top: 0em;
width: 0;
border-width: 0em 0em;
left: .55em;
}
}
@keyframes slideIn {
0% {
border-width: 0em 1.1em;
}
90% {
border-width: 2.25em 1.1em;
}
100% {
border-width: 2.25em 1.1em;
}
}
.fa-beat {
animation: fa-beat 5s ease infinite;
}
@keyframes fa-beat {
0% {
transform: scale(1);
}
5% {
transform: scale(1.5);
}
20% {
transform: scale(1);
}
30% {
transform: scale(1);
}
35% {
transform: scale(1.5);
}
50% {
transform: scale(1);
}
55% {
transform: scale(1.5);
}
70% {
transform: scale(1);
}
}
.truncate {
width: 250px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<script src="https://kit.fontawesome.com/e3a6e5f796.js" crossorigin="anonymous"></script>
<table>
<tr style="border: 0px solid #FFFFFF;" class="tr-hover" data-href="flow.asp?ShowPagePart=FlowNotDone&GetSpecificUserOnFlow=yes&UserIDOnFlow=315">
<td>
<div class="blob red" id="StatusToolTipJoinLess50Percent">
<center>
<font style="color: #FFFFFF;"><b>T</b></font>
</center>
</div>
</td>
<td>Some Name</td>
<td>28-05-2021</td>
<td>40,00 %</td>
<tr>
<tr style="border: 0px solid #FFFFFF;">
<td colspan="4">
<div role="row" class="progress shadow mb-2 bg-gray" aria-colspan="4">
<div role="cell" aria-colspan="4" class="progress-bar
bg-danger
" role="progressbar" style="width: 40%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">40,00%</div>
</div>
<table style="width: 100%;" cellpadding="1" colspan="1">
<tr id="tr_user_tasksIT_NotDone315" class="tr_user_tasks hand_user_tasks" onclick="window.location='confirm_tasks_solved.asp?RoleType=IT2&id=315';">
<td align="center" style="width: 30px;"><i class="fas fa-exclamation-triangle text-danger fa-beat"></i></td>
<td>
<div class="TaskTextSpanIT315" style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep1 - Info received - awaits you</b></font>
</div>
</td>
</tr>
<tr id="tr_user_tasksCFO315" class="tr_user_tasks hand_user_tasks" onclick="window.location='confirm_tasks_solved.asp?RoleType=cfo&id=315';">
<td align="center" style="width: 30px;"><i class="fas fa-check text-success"></i></td>
<td>
<div class="TaskTextSpanCFO315" style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep2 - Finished d. 05-05-2021</b></font>
<DIV>
</td>
</tr>
<tr id="tr_user_tasksEconomy_NotDone315" class="tr_user_tasks hand_user_tasks" onclick="window.location='sallary_info.asp?RoleType=economy&id=315';">
<td align="center" style="width: 30px;"><i class="fas fa-exclamation-triangle text-danger fa-beat"></i></td>
<td>
<div class="TaskTextSpanEconomy315" style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep 3 - Adviced 05-05-2021 - awaits you</b></font>
</div>
</td>
</tr>
<tr id="tr_user_tasksAcademy315" class="tr_user_tasks">
<td align="center" style="width: 30px;">
<div class="hourglass hourglass-small"></div>
</td>
<td>
<div style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep3 - Not yet Adviced - awaits Some Person</b></font>
</div>
</td>
</tr>
<tr class="tr_user_tasks">
<td align="center" style="width: 30px;">
<div class="hourglass hourglass-small"></div>
</td>
<td>
<div style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep4 - Not yet Adviced - awaits Some Person</b></font>
</div>
</td>
</tr>
<tr class="tr_user_tasks">
<td align="center" style="width: 30px;">
<div class="hourglass hourglass-small"></div>
</td>
<td>
<div style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep5 - Not yet Adviced - awaits Some Person</b></font>
</div>
</td>
</tr>
<tr id="tr_user_tasksWelcomePackage_NotDone315" class="tr_user_tasks hand_user_tasks" onclick="window.location='confirm_tasks_solved.asp?RoleType=WelcomePackage&id=315';">
<td align="center" style="width: 30px;"><i class="fas fa-exclamation-triangle text-danger fa-beat"></i></td>
<td>
<div class="TaskTextSpanWelcomePackage315" style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep6 - Adviced 05-05-2021 - awaits you</b></font>
</div>
</td>
</tr>
<tr id="tr_user_tasksKeyCardDone315" class="tr_user_tasks hand_user_tasks" onclick="window.location='confirm_tasks_solved.asp?RoleType=AccessKey&id=315';">
<td align="center" style="width: 30px;"><i class="fas fa-check text-success"></i></td>
<td>
<div class="TaskTextSpanKeyCardDone315" style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep7 - Finished d. 05-05-2021</b></font>
</div>
</td>
</tr>
<tr id="tr_user_tasksPortraitDone_NotDone315" class="tr_user_tasks hand_user_tasks" onclick="window.location='confirm_tasks_solved.asp?RoleType=Portrait&id=315';">
<td align="center" style="width: 30px;"><i class="fas fa-exclamation-triangle text-danger fa-beat"></i></td>
<td>
<div class="TaskTextSpanPortraitDone315" style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep8 - Adviced 05-05-2021 - awaits you</b></font>
</div>
</td>
</tr>
<tr class="tr_user_tasks">
<td align="center" style="width: 30px;">
<div class="hourglass hourglass-small"></div>
</td>
<td>
<div style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep9 - Not yet Adviced - awaits Some Person</b></font>
</div>
</td>
</tr>
<tr class="tr_user_tasks">
<td align="center" style="width: 30px;">
<div class="hourglass hourglass-small"></div>
</td>
<td>
<div style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep10 - Not yet Adviced - awaits Some Person</b></font>
</div>
</td>
</tr>
<tr class="tr_user_tasks">
<td align="center" style="width: 30px;">
<div class="hourglass hourglass-small"></div>
</td>
<td>
<div style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep11 - Not yet Adviced - awaits Some Person</b></font>
</div>
</td>
</tr>
<tr id="tr_user_tasksPhone_NotDone315" class="tr_user_tasks hand_user_tasks" onclick="window.location='confirm_tasks_solved.asp?RoleType=Phone&id=315';">
<td align="center" style="width: 30px;"><i class="fas fa-exclamation-triangle text-danger fa-beat"></i></td>
<td>
<div class="TaskTextSpanPhone315" style="width: 400px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<font style="font-size: 13px;"><b>Dep12 - Adviced 05-05-2021 - awaits you</b></font>
</div>
</td>
</tr>
</table>
</td>
<tr>
</table>
Upvotes: 1