jquery next by class fade out -


<div id="formheadtop">  <input class="checkbox" type="checkbox" /></div><div class="formbody"></div> <div id="formheadtop"> <input class="checkbox" type="checkbox" /></div><div class="formbody"></div> <div id="formheadtop"><input class="checkbox" type="checkbox" /></div><div class="formbody"></div>    $(function() { $('input:checkbox').live('click', function () { if ( $(this).attr('checked') == true )  {     $(this).nextall('.formbody:first').fadein(); } else {  $('.formbody').fadeout(); }; }); 

the code doesn't work. want fade out next div.formbody.

first we'll need change id="formheadtop" class="formheadtop", since ids must unique. can use code fade in , out divs:

jquery

$(document).ready(function(){   $('.formheadtop :checkbox').live('click', function() {     if ($(this).is(':checked')) {       $(this).parent().next('.formbody').fadein();     }  else {        $(this).parent().next('.formbody').fadeout();     };   }); }); 

you shorten $(this).parent().next('.formbody') $(this).parent().next().fadein(), put in selector, in case ever want put in between.

html

<div class="formheadtop"><input class="checkbox" type="checkbox" checked="checked" /></div> <div class="formbody">test</div> <div class="formheadtop"><input class="checkbox" type="checkbox" checked="checked" /></div> <div class="formbody">test</div> <div class="formheadtop"><input class="checkbox" type="checkbox" checked="checked" /></div> <div class="formbody">test</div> 

i made checkboxes checked default. if not, you'll need hide content in formbody tags.

here's code in action.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -