Hello I want to chnage the background to the latest radio btn clicked like in the atached image

I have made somecode but this is not doing the job I have strated like this jQuery(':radio:last:checked').lengthI thought that by this way I will get one result and I was right then I wrote it like this






        else if(jQuery(this).is(':not(':last')')){





Can somenody help me?
Thank you in advance

Have you seen the atachement before you have submited your answer this is not what I am after if you look closely at the picture that I submitted you will see that this is a more complex problem and I highlight the td not a div


you can use td instead of DIv tag.please check following e.g.

just copy below code in html file.


 <script src="http://code.jquery.com/jquery-latest.js"></script>
<td id=1>
   <input type="radio" name="1" value="1" class="hi">
 <td id="2">
    <input type="radio" name="1" value="2" class="mid">
 <td id="3">
    <input type="radio" name="1" value="3" class="mid">

$("input").click(function() {

var td_id=$(":checked").val();

Not a solution to the problem look at the picture and you will see that only the last clicked button is changing the color and teh rest remain selected without changing the color try my code out that is the closest thing I got to solve this

Can someone please help me understand where have I gone wrong?
Thank you

I'm struggling to understand what you are trying to do... which of the following?

  • The td background should only change colour when the last radio button out of all the radio buttons in the table is clicked.
  • The background colour for the radio buttons in the second column should change when they're clicked.

I have added examples of both here: http://jsfiddle.net/3NE8j/2/

Not sure if I've interpreted what you were trying to say correctly though.

Ok this is the idea when you click a radio button you get a blue bg when you click a new radio btn you get a bg to the new button and the old one gets the default bg but remains selected
Hope you understand now