1
<a class="checkModelButton" href="addrow.php">ADD ROW</a>
<table>
   <thead>
       <th>Name</th> 
   </thead>
   <tboby id="model_row">
       <tr>Nokia N70</tr>
   </tbody>
</table>

And jQuery:

jQuery('.checkModelButton').click(function(){
   var url = jQuery(this).attr('href');
   jQuery.ajax({
      type:'get',
      cache: false,
      url: url,
      success: function(html){
         jQuery('#model_row').html(html);
      }  
   });
});

in file addrow.php

<tr>Nokia N71</tr>

When I click on a tag is result is:

   <table>
       <thead>
           <th>Name</th> 
       </thead>
       <tboby id="model_row">
           <tr>Nokia N71</tr>
       </tbody>
    </table>

How to fix it to result is:

   <table>
       <thead>
           <th>Name</th> 
       </thead>
       <tboby id="model_row">
           <tr>Nokia N70</tr>
           <tr>Nokia N71</tr>
       </tbody>
    </table>

2 Answers 2

3

Use .append() OR .appendTo() instead of .html()

Like

success: function(html){
         jQuery('#model_row').append(html);
      }  

OR

 success: function(html){
             jQuery(html).appendTo('#model_row');
          }  
Sign up to request clarification or add additional context in comments.

Comments

0

Using .html() will overwrite the content.

You need to append it.

$('#model_row').append(html);

1 Comment

@AnkitGautam: I hadn't seen his html structure. I assumed it was a row which is why I used insertAfter()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.