-2

I want to hide and show the inputbox based on checkbox status. In my case both are appended by the jquery as follows:

$container.append('<li><label><input type="checkbox" style="float:left"</label>
<input type="text" name="couple_answers['+index+']" id="couple_answers_'+index+'" maxlength="500" class="input-item form-control text-field"></li>');

Please suggest me any possibilities.

Naresh
  • 5
  • 1

1 Answers1

1

$(function(){
     $('#chk').on('change',function(){
         if(this.checked) {
             $('#res').html("<input id='inp' type='text' />");
         }else{
             $('#inp').hide();
         }
     });
 });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form>
    <input type="checkbox" id="chk" checked/> Click Here    
    <br/><br/>
    <div id="res"></div>
</form>

    
Geee
  • 2,217
  • 15
  • 30
  • thanks for the answer @Ghanshyam Bhava, it is the code for displayed in html. But i want do the same while the html appended by jquery – Naresh Apr 25 '17 at 11:11
  • @Naresh, Check updated snippet. Might be it's exactly you want! – Geee Apr 25 '17 at 11:27