jquery - Can't remove class from previously selected radio button -


what i'm trying have user click table selects radio button inside table , add class table selected. if user selects table when radio checked class added, class selected table/radio needs removed well.

right of works, accept when select radio previous class isn't removed. if toggle radio removed.

here's link demo on jsfidd can see html , other js.

$(function() {      $('table').click(function(event) {          if (event.target.type != "radio") {              var = $(this).find('input:radio');              that.attr('checked', !that.is(':checked'));              if (that.is(':checked')) {             that.closest('table').addclass('selected');             }             else {                 that.closest('table').removeclass('selected');             }         }      }); }); 

i forgot using version before modified that. in 1 if click radio button style add/remove correctly not when click table. attempted combine 2 , thats how got function posted above..

this link jsfiddle demo , here jquery used too.

// jquery select radio button within clicked table $(function() {  $('table').click(function(event) {        if(event.target.type != "radio") {          var = $(this).find('input:radio');         that.attr('checked', !that.is(':checked'));      } }); });  // jquery change style of table containing selected radio button $(function() { $('input[type="radio"]').change( function() {   //   grab radio buttons same name 1 changed     var this_radio_set = $('input[name="'+$(this).attr("name")+'"]');      (var i=0; < this_radio_set.length;i++) {     if ( $(this_radio_set[i]).is(':checked') )                $(this_radio_set[i]).closest('table').addclass('selected');         else          $(this_radio_set[i]).closest('table').removeclass('selected'); } }); });  

you'll need this:

$(this).closest('.container').addclass('selected').parent().siblings().each(function() {     $(this).find('.container').removeclass('selected'); }); 

and demo: http://jsfiddle.net/cgtym/22/


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -