tom91136
tom91136

Reputation: 8962

jQuery unable to work with appended content

in jQuery, how do i load an generated HTML and do some manipulation to it?

First: load my HTML from another page:

$.post("my_page.php?operation=show_data&session=<?php echo SESSION_UUID;?>", 
        function(data){
            $("#data-table").empty().append();
        }
    );

now, i can't do the following:

//the .preview-table is in the appended HTML
$(".preview-table").dataTable( {}); // this is a plugin jQuery plugin

and yes i've read that i can use .live() but then it works on events only...

how do i load the plugin to the selector properly?

DataTable plugin: http://datatables.net/

Upvotes: 0

Views: 74

Answers (1)

karim79
karim79

Reputation: 342635

$.post("my_page.php?operation=show_data&session=<?php echo SESSION_UUID;?>", 
        function(data){
            $("#data-table").empty().append(data);

            // now that the elements have been replaced,
            // re-initialise plugin
            $(".preview-table").dataTable(options);
        }
    );

Upvotes: 3

Related Questions