How i can widget ID get after drag for wordpress with jquery?

I create custom widget with select option image but first time selected option image are not showing after saving this function work perfectly,I need this function only load after Drag in sidebar then load function?

jQuery(document).ready(function() {
    jQuery('body').on('change', '.selector', change_image);     
    function change_image(){
        var $path = jQuery(this).find('option:selected').val();
        jQuery('.image_path').attr('src',$path);
    }
});

Related posts

1 comment

  1. My jquery function working perfectly in sidebar :). Jquery Enable after Dragging widget in sidebar .

    jQuery( document ).ajaxComplete( function( event, XMLHttpRequest, ajaxOptions ) {
        var request = {}, pairs = ajaxOptions.data.split('&'), i, split, widget;
        for( i in pairs ) {
            split = pairs[i].split( '=' );
            request[decodeURIComponent( split[0] )] = decodeURIComponent( split[1] );
        }
    
        if( request.action && ( request.action === 'save-widget' ) ) {
    
            widget = jQuery('input.widget-id[value="' + request['widget-id'] + '"]').parents('.widget');
            if( !XMLHttpRequest.responseText ) 
                wpWidgets.save(widget, 0, 1, 0);
            else
              jQuery('.selector').on('change', change_image);   
    
            function change_image(){
    
                    var $path = jQuery(this).find('option:selected').val();
                    jQuery('.image_path').attr('src',$path);
            }   
    
        }
    });
    

Comments are closed.