This piece of code below allows me to be able to set the text input to 1, if there are no answer buttons turned on from the chosen option "True or False".\[code\] var container = $btn.closest(".optionAndAnswer"); // here the zero gets assigned var answertxt = $(".answertxt", container); var numberison = $(".answerBtnsOn", container).length; var maxRowValue = http://stackoverflow.com/questions/13842003/$('.gridTxt', container).val();if (maxRowValue =http://stackoverflow.com/questions/13842003/=='True or False') { if (answertxt.val() == 1 && numberison == 0) { numberison = 1; }}\[/code\]Below is the relevant html the above code controls:\[code\] <table id="optionAndAnswer" class="optionAndAnswer">... <td><input type="text" name="gridValues" class="gridTxt maxRow" id="mainGridTxt"readonly="readonly" /> </td>... <td> <input type="text" name="numberAnswer" class="numberAnswerTxt answertxt" id="mainNumberAnswerTxt" readonly="readonly" onChange="getButtons()"> </td>... <td> <input class="answerBtns answers answerBtnsOff" name="answerName[True]" id="answerTrue" type="button" value="http://stackoverflow.com/questions/13842003/True" onclick="javascript: btnclick(this, -1, true);" /> <input class="answerBtns answers answerBtnsOff" name="answerName[False]" id="answerFalse" type="button" value="http://stackoverflow.com/questions/13842003/False" onclick="javascript: btnclick(this, -1, true);" /> </td>...</table>\[/code\]But my question is the how can I write a similar code for the function below where the html is: In the function below it appends the top html of the selected option, answers and number of answers into an appended table row:\[code\]function insertQuestion(form) { var context = $('#optionAndAnswer'); var currenttotal = context.find('.answerBtnsOn').length; var $questionType = ''; gQuestionIndex++; $('.gridTxt', context).each( function() { var $this = $(this); var $optionsText = $("<input type='text' class='gridTxtRow maxRow' readonly='readonly' />") .attr('name',$this.attr('name')+"[]") .attr('value',$this.val()) .appendTo( $options ) .after("<span href='http://stackoverflow.com/questions/13842003/#' class='showGrid'>[Open Grid]</span>"); $questionType = $this.val(); });$('.numberAnswerTxt', context).each(function() { var $this = $(this); var $noofanswersText = ''; if ($questionType == 'True or False'){ $noofanswersText = $("<span class='naRow string' style='display: block;'>Only 1 Answer</span><input type='text' class='numberAnswerTxtRow answertxt' style='display: none;' onkeyup='numberKeyUp(this)' onkeypress='return isNumberKey(event)' onChange='getButtons()'>").attr('name', $this.attr('name')+"[]").attr('value', $this.val()); }else{ $noofanswersText = $("<span class='naRow string' style='display: none;'>Only 1 Answer</span><input type='text' class='numberAnswerTxtRow answertxt' style='display: block;' onkeyup='numberKeyUp(this)' onkeypress='return isNumberKey(event)' onChange='getButtons()'>").attr('name', $this.attr('name')+"[]").attr('value', $this.val()); } $noofanswers.append($noofanswersText); }); var $this, i=0, $row, $cell;$('#optionAndAnswer .answers').each(function() { $this = $(this); if(i%7 == 0) { $row = $("<tr/>").appendTo($answer); $cell = $("<td/>").appendTo($row); } var $newBtn = $(("<input class='answerBtnsRow answers' type='button' style='display:%s;' onclick='btnclick(this, " + gQuestionIndex + ");' />").replace('%s', $this.is(':visible') ? 'inline-block' : 'none')).attr('name', "value[" + gQuestionIndex + "][]").attr('value', $this.val()).attr('class', $this.attr('class')).attr('id', $this.attr('id') + 'Row'); $newBtn.appendTo($cell); i++;});}\[/code\]UPDATE:Below is the HTML of when a row is appended into a table:\[code\]<table id="optionAndAnswer" class="optionAndAnswer">... <td><input type="text" name="gridValues" class="gridTxtRow maxRow" id="mainGridTxt"readonly="readonly" /> </td>... <td> <input type="text" name="numberAnswer" class="numberAnswerTxtRow answertxt" id="mainNumberAnswerTxt" readonly="readonly" onChange="getButtons()"> </td>... <td> <input class="answerBtns answers answerBtnsOff" name="answerName[True]" id="answerTrue" type="button" value="http://stackoverflow.com/questions/13842003/True" onclick="javascript: btnclick(this, 1, true);" /> <input class="answerBtns answersRow answerBtnsOff" name="answerName[False]" id="answerFalse" type="button" value="http://stackoverflow.com/questions/13842003/False" onclick="javascript: btnclick(this, 1, true);" /> </td>...</table>\[/code\]Only difference between the html appended into a table and html at top of question is the class names