Jump to content

Change Background of a table row when value changes


Temnis

Recommended Posts

Hey guys!

 

I have a stupid questions! I have a table with some rows. Every row has its unique id.

<table id="CONNECTION">    <tr id="id1">        <td>1</td>        <td>0</td>    </tr>    <tr id="id2">        <td>2</td>        <td>0</td>    </tr></table>

Now I want to write a function. Something like popGreen($rowID). That function should change the background color of a single row to green. After that, the background color should slowly fade away.

 

How do I do that? I'm pretty sure there is an easy way to do this with jQuery, but I don't know where to start.

 

Any Ideas?

Link to comment
Share on other sites

table with editable cells

            $(function() {                $('#CONNECTION td').each(function() {                    $(this).attr('contenteditable', 'true');                    $(this).attr('data-value', $(this).html());                });                $('#CONNECTION td').on('blur', function() {                    if ($(this).html() != $(this).attr('data-value'))                    {                        $(this).parent().css({'background-color': 'green'});                        $(this).parent().animate({'background-color': 'transparent'}, 900);                        $(this).find('br').remove();                        $(this).attr('data-value', $(this).html());                    }                });            });
Edited by dsonesuk
Link to comment
Share on other sites

Or if you want to keep your js and styles separate. After you get the value you can add a class such as 'greenRow' with a transition property and then remove the class. The transition will create the effect but only in browsers that support it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...