How do I store the span tag next to the textbox?
<p>Hi below I have a javascript code where what should happen is that it it appends a textbox and the [Open Grid] (which is in a span) next to the textbox. The textbox is stored in an array +"[]" so I tried putting the span after the textbox using .after() but the problem is that even though it displays the textbox, it does not display the span [Open Grid]. How can I get the hyperlink to be displayed next to the textbox?</p>

<p>Below is the code:</p>

<pre><code>    &lt;script&gt;

    $(document).on('click','.showGrid', function(e) {

        $(".gridBtns").removeClass("gridBtnsOn");

        var value = $(this)
            .siblings('input[name=gridValues]').val();

        $("#btn" + value.replace(/\s/g, '')).addClass("gridBtnsOn");

        $('.optionTypeTbl').fadeToggle('slow');
        $(this).parent().append($('.optionTypeTbl'));
        $('.optionTypeTbl').css({

            left: $(this).position().left,
            top: $(this).position().top + 20

        });

        e.stopPropagation();

    });


        function insertQuestion(form) {   

        var context = $('#optionAndAnswer');

        var $tbody = $('#qandatbl &gt; tbody'); 
        var $tr = $("&lt;tr class='optionAndAnswer' align='center'&gt;&lt;/tr&gt;");
        var $options = $("&lt;td class='option'&gt;&lt;/td&gt;");

        $('.gridTxt', context).each( function() {

var $this = $(this);
var $optionsText = $("&lt;input type='text' class='gridTxtRow maxRow' readonly='readonly' /&gt;")
    .attr('name',$this.attr('name')+"[]")
    .attr('value',$this.val())
    .appendTo( $options )
    .after("&lt;span href='#' class='showGrid'&gt;[Open Grid]&lt;/span&gt;");

    $questionType = $this.val();


        });

        $tr.append($options);    
        $tbody.append($tr); 

        }

    &lt;/script&gt;


    &lt;form id="QandA" action="insertQuestion.php" method="post" &gt;


    &lt;table id="optionAndAnswer" class="optionAndAnswer"&gt;
    &lt;tr class="option"&gt;
    &lt;td&gt;Option Type:&lt;/td&gt;
    &lt;td&gt;
    &lt;div&gt;
        &lt;input type="text" name="gridValues" class="gridTxt maxRow" readonly="readonly" /&gt;
        &lt;span href="#" class="showGrid" id="showGridId"&gt;[Open Grid]&lt;/span&gt;
    &lt;/div&gt;
    &lt;table class="optionTypeTbl"&gt;
    &lt;tr&gt;

        &lt;?php
        $i = 1;
        foreach($num as $key =&gt; $val){
            if($i%7 == 1) echo"&lt;tr&gt;&lt;td&gt;";
            echo"&lt;input type=\"button\" value=\"$val\" id=\"btn".$val."\" name=\"btn".$val."Name\" class=\"gridBtns gridBtnsOff\"&gt;";        
            if($i%7 == 0) echo"&lt;/td&gt;&lt;/tr&gt;";
            $i++;
        }
        ?&gt;

            &lt;/tr&gt;
            &lt;tr&gt;
            &lt;td&gt;
            &lt;input class="gridBtns" name="btnTrueorFalseName"  id="btnTrueorFalse"  type="button"  value="True or False"  /&gt;
            &lt;input class="gridBtns" name="btnYesorNoName"  id="btnYesorNo"  type="button"  value="Yes or No"  /&gt;
            &lt;/td&gt;
            &lt;/tr&gt; 
            &lt;/table&gt;

            &lt;/td&gt;
    &lt;/tr&gt;
    &lt;/td&gt;
    &lt;/tr&gt;
    &lt;/table&gt;


    &lt;/form&gt;
</code></pre>
