tags:

views:

34

answers:

1

Hi guys,

Can anyone tell me, can I invoke third party jquery funcation from html return by ajax call please ?

The problem I am facing is, there is an ajax call, returning some chunk of html (html for jquery datatable). In this html there is one link to add a new row to the table when clicked. To add this new row dynamically I am calling jquery data table's fnOpen() function, but it's not working. If I don't use ajax call and write html by myself it works properly. The jquery datatable script is at client side, it's not being returned as part of an ajax call.

Any help is appreciated.

Thank you
Arya

A: 

I've run into a similar issue before. Difficult to diagnose exactly with no code example though.

This is probably happening because the link (which I'm assuming is just an object you're assigning an onClick even to?) has not been loaded before you are assigning this click event.

Try assigning the click event to the link object after the ajax call has completed. This should solve you're problem.

so it would be something like:

//ajax call
$.get(somepage,function(data){
    //do some formating of data and probably insert into html?
    //once new links have been inserted into html, assign click event.
    $(".linkClass").click(function(){fnOpen()});
});
Nick011