javascript - Auto increment step number if element is visible -
javascript - Auto increment step number if element is visible -
attempting auto increment step numbers form. elements of form may hide or show dependent on answers above. html
<div class="confirmation-step"> <span class="step-number"></span> </div> <div class="confirmation-step" style="display:none;"> <span class="step-number"></span> </div> <div class="confirmation-step"> <span class="step-number"></span> </div> jquery
$('.confirmation-step').each(function() { if($(this).is(':visible')) { //set variable stepnum //haven't come yet } else {} $(this).find('.step-number').html(stepnum); }); sample output
<div class="confirmation-step"> <span class="step-number">1</span> </div> <div class="confirmation-step" style="display:none;"> <span class="step-number"></span> </div> <div class="confirmation-step"> <span class="step-number">2</span> </div> thanks!
how about
$('.confirmation-step:visible .step-number').text(function(i) {return i+1;}); fiddle
javascript jquery html
Comments
Post a Comment