How can I disable hover and active effects from jQuery?

I have a table with 10 <tr> tags. My CSS has a hover and active effect going on with these 10 rows. Each of these 10 <tr> tags have an attribute of custID. What I am trying to accomplish is to disable the hover and active effects if this custID has a value of -1. Here is the code snippet, please look for my /****** comments ******/, that will lead you to what I'm asking about:

<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<style>
    #gridContents tr {
        background: lightgray;
        cursor: pointer;
        -webkit-user-select: none;
        -moz-user-select: none;
        -o-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    #gridContents tr:nth-child(2n) {
        background: #A3C5FF;
    }
    
    #gridContents tr:hover {
        background: #FFF6C7;
        cursor: pointer;
    }
    
    #gridContents tr:active {
        background: yellow;
    }

    #gridContents tr.selectedRow { /* This is the class I'm toggling */
        background: green;
    }
        
</style>
<script type="text/javascript">
$(function() {
    $("#gridContents").mouseover(function() {
        if ($(this).attr("custID") === "-1") {
            /*******************************************************
            I'd like to disable the hover and active effect here because
            custID is -1. How can I do this?
            *******************************************************/
        }
    });
});
</script>
</head>
<body>
<table id="gridContents">
    <tr custID="1"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="2"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="3"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="4"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="5"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="6"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="7"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="8"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="-1"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="-1"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
</table>
    <div id="timer"></div>
</body>
</html>

Open in new window


Thanks in advance!
elepilAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

skijCommented:
If you could add a class attribute to the inactive rows, no jQuery would be needed for this.
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
    #gridContents tr {
        background: lightgray;
        cursor: default;
        -webkit-user-select: none;
        -moz-user-select: none;
        -o-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    #gridContents tr:nth-child(2n) {
        background: #A3C5FF;
    }
    
    #gridContents tr:hover:not(.inactive) {
        background: #FFF6C7;
        cursor: pointer;
    }
    
    #gridContents tr:active:not(.inactive) {
        background: yellow;
    }

    #gridContents tr.selectedRow { /* This is the class I'm toggling */
        background: green;
    }
        
</style>
</head>
<body>
<table id="gridContents">
    <tr custID="1"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="2"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="3"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="4"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="5"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="6"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="7"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="8"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr class="inactive" custID="-1"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr class="inactive" custID="-1"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
</table>
    <div id="timer"></div>
</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
skijCommented:
If you insist on using jQuery, you could do this:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<style type="text/css">
    #gridContents tr {
        background: lightgray;
        cursor: default;
        -webkit-user-select: none;
        -moz-user-select: none;
        -o-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    #gridContents tr:nth-child(2n) {
        background: #A3C5FF;
    }
    
    #gridContents tr:hover:not(.inactive) {
        background: #FFF6C7;
        cursor: pointer;
    }
    
    #gridContents tr:active:not(.inactive) {
        background: yellow;
    }

    #gridContents tr.selectedRow { /* This is the class I'm toggling */
        background: green;
    }
        
</style>

<script type="text/javascript">
$(function() {
    $("#gridContents tr[custID=-1]").addClass('inactive');
});
</script>

</head>
<body>
<table id="gridContents">
    <tr custID="1"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="2"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="3"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="4"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="5"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="6"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="7"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="8"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="-1"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="-1"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
</table>
    <div id="timer"></div>
</body>
</html>

Open in new window

0
skijCommented:
Or:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<style>
    #gridContents tr {
        background: lightgray;
        cursor: pointer;
        -webkit-user-select: none;
        -moz-user-select: none;
        -o-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    #gridContents tr:nth-child(2n) {
        background: #A3C5FF;
    }
    
    #gridContents tr:hover {
        background: #FFF6C7;
        cursor: pointer;
    }
    
    #gridContents tr:active {
        background: yellow;
    }

    #gridContents tr.selectedRow { /* This is the class I'm toggling */
        background: green;
    }
        
</style>
<script type="text/javascript">
$(function() {
    $("#gridContents tr[custID=-1]:nth-child(1n)").mouseover(function() {
      $(this).css('cursor','default');
      $(this).css('background','lightgray');
    });
    $("#gridContents tr[custID=-1]:nth-child(2n)").mouseover(function() {
      $(this).css('cursor','default');
      $(this).css('background','#A3C5FF');
    });
});
</script>
</head>
<body>
<table id="gridContents">
    <tr custID="1"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="2"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="3"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="4"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="5"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="6"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="7"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="8"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="-1"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
    <tr custID="-1"><td>12345</td><td>Doe</td><td>John</td><td>8005551212</td><td>8005551213</td><td>8005551214</td><td>8005551215</td></tr>
</table>
    <div id="timer"></div>
</body>
</html>

Open in new window

0
elepilAuthor Commented:
skij, I like the first one (the one I marked as best) because it is simplest.

Thank you very much for your help. Greatly appreciated!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.