0

I have a button in my table, I want to remove a complete row on button click.? please dont try to modify the logic i used.

Currently when the button is clicked I get its id and based on that id i need to delete an element(complete row) from the DOM having same class name.

JavaScript

$(".removeAKA").click(function () {
    // alert($(this).val());
    var id = this.id;
    alert(id);
    $("." + id).remove();
});

​HTML

<tr class="aka 1" id="sdf">
  <td>AKA 1</td>
  <td><input class="text-box single-line" id="aka_1_" name="aka[1]" type="text" value="2" /></td>
  <td><input type="button" class="removeAKA" id="aka 1" value="Delete" /></td>
</tr>​

Here is my code in a jsfiddle

Manse
  • 37,765
  • 10
  • 83
  • 108
RollerCosta
  • 5,020
  • 9
  • 53
  • 71

6 Answers6

3

Hiya demo if you want to keep the spaces: http://jsfiddle.net/59RA2/9/ OR http://jsfiddle.net/59RA2/31/ OR http://jsfiddle.net/59RA2/32/

Hope this helps.

I have replaced spaces to . because spaces is not recognized when Jquery tries interpreting your code.

or

You can also use $(this).closest('tr').remove(); to remove the row.

or You can use $("table ."+id).remove();

Further:

jQuery: selector (classname with space)

jQuery remove table row with non-standard id characters

Quote

Class names can't have spaces in them. What you have there is two classes:

This div has two classes: panel and current. That's easily selected:

$("div.panel.current")... That means select all divs that have class panel and class current.

Code

just replace spaces with . and it will work if you want to else you can have no spaces in-between.

Have a good one, cheers!

Community
  • 1
  • 1
Tats_innit
  • 33,991
  • 10
  • 71
  • 77
0

Class names and IDs can't have spaces in them. Remove the spaces, format your HTML properly, and it will work.

Your example: http://jsfiddle.net/EFmRM/7/

Isolated example: http://jsfiddle.net/Pz5pF/

Christian
  • 19,605
  • 3
  • 54
  • 70
  • but i want my id attribute like abc@i .because i am assigning id to multiple buttons inside for loop – RollerCosta Apr 12 '12 at 10:28
  • Can you elaborate on the issue/provide more code? As I mentioned, class names *cannot* have spaces in them. A space in the class attribute acts as a separator. – Christian Apr 13 '12 at 02:32
0

try this

$(".removeAKA").click(function () { 
   $(this).remove();
});

//id should not contain spaces

Madan
  • 691
  • 5
  • 20
0

try

$(this).parent().remove();
ShurikEv
  • 170
  • 1
  • 10
0

remove space in the id and classname. This is not a proper naming convention. Use 'aka1' or 'aka_1' instead of 'aka 1' .Then your code will work.

Valli69
  • 8,856
  • 4
  • 23
  • 29
0

Try this one...

$(this).parent().remove();

I have tested this one in jsfiddle.

naim shaikh
  • 1,103
  • 2
  • 9
  • 20