6

I have following css rule for table row background,

tr.unread {
    background:rgba(237, 239, 245, 0.70) none repeat scroll 0 0;
   -webkit-transition: background 1s linear;
   -moz-transition: background 1s linear;
   -o-transition: background 1s linear;
   transition: background 1s linear;
 }

I want to remove the .unread class from tr with fading out animation (without Javascript / Jquery if possible). But it just removes the class without any animation.

Javascript: $('tr.unread').removeClass('unread');

Any Ideas ?

3
  • Are you using jquery-ui? Commented Jul 4, 2015 at 10:11
  • No. Using jquery only. Commented Jul 4, 2015 at 10:12
  • 1
    absolutely no need for JQueryUI for this, add and remove class is all you should be doing with the js Commented Jul 4, 2015 at 11:49

1 Answer 1

4

Transition rules must be defined on the tr element:

$('button').click(function() {
  $('tr.unread').removeClass('unread');
});
tr {
    -webkit-transition: background 1s linear;
    -moz-transition: background 1s linear;
    -o-transition: background 1s linear;
    transition: background 1s linear;
}
tr.unread {
    background: rgba(237, 239, 245, 0.70) none repeat scroll 0 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
    <tr class="unread">
        <td>
            <td>Table Cell 1</td>
            <td>Table Cell 2</td>
        </td>
    </tr>
    <tr class="unread">
        <td>
            <td>Table Cell 1</td>
            <td>Table Cell 2</td>
        </td>
    </tr>
</table>

<button>Mark read</button>

Sign up to request clarification or add additional context in comments.

5 Comments

Cool. But any other solutions except adding animation property in tr element. Because I have many other tables in other pages and I don't want to affect them.
You should use another class. Just make something like animated.unread instead of tr.unread and put animation to animated.
I mean is there any way except altering original tr rule ?
You can limit this behavior for one table with some class. Like <table class="messages"> and in CSS: .messages tr {-webkit-transition: ...}
you can just add a class message then add and remove the unread class from that class, no need to mention HTML structure at all in the css or the jquery, then, when you apply it elsewhere or stop using tables it will still just work :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.