I'm having trouble trying to find the proper way to make it work :
I got a table that with multiple cells :
$('tr > td').click(function()
each time the cell is clicked, I add to this cell an input and 2 buttons (one button is to validate, other one is to delete the whole thing in the cell so it deletes the input and both buttons)
The problem is when I click on the delete button it also triggers the
$('tr > td').click(function()
so what it does is that it removes the input and the 2 buttons but add it back.
what I need is that :
if cell is empty : add input + 2 buttons if remove button is clicked : remove input + 2 buttons from the cell cell can only have 1 time the input and 2 buttons (so no multiples inputs and more than 2 buttons)
I've been trying to make it right by using toggleClass and using if statement with hasClass but it never goes as I want to.
Thanks for your help, hope you can fill my lack of logic.
EDIT :
function remove()
{
event.stopPropagation();
$(this).parent().
$(this).parent().toggleClass('removed');
$(this).prev().prev().remove();
$(this).next().next().remove();
$(this).remove();
}
$('tr > td').click(function(event)
{
if ($(this).hasClass("done") == false && $(this).hasClass("removed") == false)
{
$(this).toggleClass("done");
$(this).append("<input class='form-control' style='height:25px;width:105px;' type='text'></input>");
$(this).append("<button onclick='remove();' type='button' id='removeUser' class='btn btn-xs'><span class='text-danger glyphicon glyphicon-remove'></span></button>");
$(this).append("<button type='submit' id='addUser' class='btn btn-xs'><span class='text-success glyphicon glyphicon-ok'></span></button>");
}
TD can only have 1 [input+2buttons]
If remove button is clicked, [input+2buttons] is removed
If TD is clicked and TD is empty, add [input+2buttons]
Sorry for being late it was launch time :)