i got a problem with a custom image upload field in wordpress. here’s the jquery for the upload button.

jQuery(function(jQuery) {

jQuery('.custom_upload_image_button').click(function() {
    formfield = jQuery(this).siblings('.custom_upload_image');
    preview = jQuery(this).siblings('.preview_image');
    tb_show('', 'media-upload.php?TB_iframe=true');
    window.send_to_editor = function(html) {
        imgurl = jQuery('img',html).attr('src');
        classes = jQuery('img',html).attr('class');
        id = classes.replace(/(.*?)wp-image-/, '');
        preview.attr('src', imgurl);
    return false;

jQuery('.custom_clear_image_button').click(function() {
    var defaultImage = jQuery(this).parent().siblings('.custom_default_image').text();
    jQuery(this).parent().siblings('.custom_preview_image').attr('src', defaultImage);
    return false;
}); });

and here comes the html for the whole thing:

<input name="'.$field['id'].'" type="hidden" class="custom_upload_image" value="'.$meta.'" />
            <img src="'.$image.'" class="preview_image" alt="" /><br />
                <input class="custom_upload_image_button button" type="button" value="Choose Image" />
                <small> <a href="#" class="custom_clear_image_button">Remove Image</a></small>
                <br clear="all" /><span class="description">'.$field['desc'].'</span>

I don’t get why classes cannot grab the class, I even created this preview image.png

Read more here: Jquery: window.send_to_editor not working – classes undefined


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: