Creating a new div onclick wordpress+ajax

To add action for WordPress AJAX

If you needed to create an AJAX handler for an “render_admin_charts_page” request, you would create a hook like this:

add_action( 'wp_ajax_render_admin_charts_page', 'yourfunction' );

function yourfunction() { ?>
    <div class="wrap">
        <div class="em-bookings-events">
            <h2><?php esc_html_e('Event Booking Report','dbem'); ?></h2>        
            <?php em_bookings_events_table(); ?>
        </div>
    </div>
<?php   // Handle request then generate response using WP_Ajax_Response
}

Using the above example, any time an AJAX request is sent to WordPress, and the request’s ‘action’ property is set to ‘render_admin_charts_page’, this hook will be automatically executed. For example, the following code would execute the above hook:

jQuery.post(
    ajaxurl, 
    {
        'action': 'render_admin_charts_page',              
    }, 
    function(response){
        alert('The server responded: ' + response);
    }
);