0

I want to remove remove table row from table and subsequently remove the item from database also.

The html generated is from ajax call at page load that gets the html from the php file.

$.ajax({
    type: "GET",
    url: "http://localhost/zabjournal/author/submit/progress",
    data: {returnSubmissions:1},
    success: function(response) {
            $('#activeSubmissions').html(response);
    }
});

In that PHP file I have define like this

$str = '<table class="zebra-striped">';
$i=1;
foreach ( $arr as $article)
{
        $str.= "<tr id=".$article->article_id.">
        <td>".$i."</td>
        <td>".$article->first_name." ".$article->last_name."</td>
        <td>".$article->title."</td>
        <td>".$article->date_submitted."</td>
        <td>
            <a class='btn primary'>View</a>
            <a class='btn'>Edit</a>
            <a class='btn error'>Delete</a></td>
        </td>
        </tr>";
    $i++;           
}
$str.='</tbody></table>';

echo $str;

Its my jQuery function to remove the table row

    $('a.btn error').click(function(){
    alert('az'); //alert wasnt even called
    var id = $(this).closest('tr').attr("id");
        $.ajax({
            type: "POST",
            url: "http://localhost/zabjournal/author/submit/progress",
            data: {article_id:id},
            success: function(response) {
             alert(id);
            }
        });
    });

But when I click the delete button, there is no action?

1 Answer 1

1

with your selector, you are searching a tag "error" inside a tag "a" which has class "btn".

Try replacing :

$('a.btn error')

by :

$('a.btn.error')

In this case you will correctly search a tag "a" with both classes "btn" and "error".

Sign up to request clarification or add additional context in comments.

9 Comments

Its still not being called, I have checked from my code, I dont know what is causing this.
Have you checked your generated html table ? Can you show us the result ? Edit : Oh, just found another mistake in your code : "$str.='</tbody></table>';" => You are closing "tbody" which is not opened before in your code.
well that must have been mistake in formatting code here, but the html is fine on notepad++
Also I am placing the table in a div element
So is your alert('az') called with all remarks i did ? i tried a simple example in jsfiddle and it works for me
|

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.