user3886613
user3886613

Reputation: 35

I cant delete rows created dynamically using jquery ajax

I cant delete rows created by ajax and jquery. I have a first page with add-0customer.php ans ajax page with ajax_add_country.php. I want to delete rows with id one<?php echo $cnt ?>. These rows are created dynamically using jquery ajax.

ajax_add_country.php contain

 $cnt=$_POST['cnt'];
<tr id="one<?php echo $cnt ?>">
  <td><input type="text" name="country2[]" 
  value="<?php echo $coun_real_name;?>"     class="shorttext"/>
  <input type="hidden" name="country[]"
  value="<?php echo $country;?>"  class="shorttext"/>
  </td>
 <td><input type="text" name="currency[]"
 value="<?php echo $currency;?>" class="shorttext" /></td>
 <td><textarea name="bank[]" cols="" rows=""><?php echo $bank;?></textarea></td>
 <td><input type="text" name="exchange_rate[]" 
  value="<?php echo $exchange_rate;?>"  class="shorttext"/></td>
 <td><p onclick="deletes(one<?php echo $cnt ?>)"> Delete  </p></td>

My delete function in add_customer.php

function deletes(id)
 {
    $('#id').remove();
  }

Anybody help me?

Upvotes: 2

Views: 214

Answers (3)

Bhushan Kawadkar
Bhushan Kawadkar

Reputation: 28513

You need to concatenate passed id with '#' like below

function deletes(id)
{
    $('#'+id).remove();
}

Note - make sure that all ids should be unique throughout the html.

Upvotes: 1

Kyi Kyi Thant
Kyi Kyi Thant

Reputation: 92

Try

$('table tr#one').remove();

or

$("#test tr:eq('one')").remove();

or

$('#one').remove();

Upvotes: 0

Luca Davanzo
Luca Davanzo

Reputation: 21520

With this query:

$('#id').remove();

Your are searching an element that has ( ID === "#id" ) means as string.

As already suggested, use:

$('#' + id).remove();

Upvotes: 0

Related Questions