3

I'm trying to execute a jquery script on the click of a button in a custom tab of the media manager, but it does not seem to work. I have been told this might be due to the button not being loaded before the script is.

The jquery script is some variation on this, currently (I tried a few different methods around it but with no success) :

jQuery( document ).on('click', '.upload_url_list_button', function() 
{
    console.log("test");
});

And the function loaded within the custom tab is

function custom_media_upload_tab_content() 
{
    ?>
        <form method="post">
            Select file to upload:
            <input type="file" name="fileToUpload" id="fileToUpload">
            <input id="upload_url_list" name="upload_url_list" class="upload_url_list_button button" type="button" value="Upload Image" name="submit">
        </form>
    <?php
}

The script is loaded correctly when I try to click it, with no results. I have also tried to load the script during the generation of the page, with

wp_enqueue_script('upload_file_list', get_template_directory_uri().'/js/upload_file_list.js', array('jquery'), '1.0', true );
wp_localize_script('upload_file_list', 'file_list', array(
            'ajax_url'  => admin_url( 'admin-ajax.php' ),
));

moved to it, but then the script just doesn't load at all.

What method should I use to execute that script there?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.