0

js output:

$(document).ready(function() {

        $('#datatable').dataTable({
            "bProcessing": true,
            "bServerSide": true,
            "sPaginationType": "full_numbers",
            "sAjaxSource": "includes/list.php",
            "sServerMethod": "POST"

        });


        $('.deleteRow').click(function() {
            alert("wait...");
        });


});

server-side php output:

<tr class="odd">
<td class="">lorem ipsum</td>
<td class="">lorem ipsum</td>
<td class="">lorem ipsum</td>
<td class="">lorem ipsum</td>
<td class="">lorem ipsum</td>
<td class=""><a class="deleteRow">delete</a></td>
</tr>

when i click delete no alert..

but when i put this delete link in my page manuelly (not php output) function working good..

3 Answers 3

1

Elements which will come after the page loaded you need to use .on()

       $(document).on('click','.deleteRow',function() {
            alert("wait...");
        });
Sign up to request clarification or add additional context in comments.

3 Comments

Just because they are dynamic doesn't mean they need to use the delegated form of .on() - though it's probably the best way - but you can always bind after the elements exist in the dom ^.^
I didn't downvote - your answer will fix his problem though - I gave you a +1
But some persons dont have any wrk .They are doing like this with out any comment
1

Use Delegate

$(document).on('click','.deleteRow',function() {
            alert("testing");
        });

2 Comments

this does the same exact thing as the OP's element.click(function() - read the first sentence from the .click() documentation This method is a shortcut for .on('click', handler)
i updated the answer ,sorry for the mistake ,thanks for the corection
0

Try this:

$('.deleteRow').on('click', function() {
     alert("wait...");
});

Edit: As others have said, the correct way is...

$(document).on('click', '.deleteRow', function() {
     alert("wait...");
});

3 Comments

this does the same exact thing as the OP's element.click(function()- read the first sentence from the .click() documentation This method is a shortcut for .on('click', handler)
ahh yes. I always mix the syntax up for that. I guess this syntax is working for me because I'm using knockoutjs and have a dom element already present? Thanks for the correction.
Yes, as long as the element is present at the time of binding then it will work with no problem.. Delegation allows for you to bind to an ancestor(higher up) element - which will listen for the event as they bubble up to it and handle it there. Therefore the element getting the event handler bound to it must also exist and be static

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.