0

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

jQuery(document).ready(function(){

    jQuery(':radio:checked').click(function(){



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

        jQuery(this).closest('td').css('background','blue');

        }

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

        jQuery(this).closest('td').css('background','none');


        }

    });



});

Can somenody help me?
Thank you in advance

Attachments jquery_radio_selection.png 6.6 KB
3
Contributors
7
Replies
10
Views
5 Years
Discussion Span
Last Post by dany12
0

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

0

Hello,

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

just copy below code in html file.

<html>

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

    </tr>
</form>
<script>
$("input").click(function() {

$("td").css('background','white');
var td_id=$(":checked").val();
$('#'+td_id).css('background','blue');
});
</script>
</body>
</html>

Edited by rajengg

0

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

0

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

0

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.

Edited by JJenZz

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.