Support » Developing with WordPress » how to trigger the click event of a Gutenberg block button

  • I am trying to trigger the click even of the media library button of an image block.

    function(event){
    		var element = event.target,
    			$element = $(element);
    		
    		if( $element.hasClass( 'components-placeholder' ) ){
    			var $notice = $element.find('.components-notice');
    			console.log('wp block added', $element, $notice );
    			if( $notice.hasClass('components-notice is-error') && $notice.find( '.components-notice__content' ).text().substring( 'It appears this file is already present in your media library:' ) !== -1 ){
    				console.log( $._data( $notice.parent().parent().find( '.components-placeholder__fieldset > .editor-media-placeholder__button')[0], "events" ) );
    				console.log('error message added', $notice.parent().parent().find( '.components-placeholder__fieldset > .editor-media-placeholder__button'));
    				$notice.parent().parent().find( '.components-placeholder__fieldset > .editor-media-placeholder__button')[0].click(); //does not work or
    $notice.parent().parent().find( '.components-placeholder__fieldset > .editor-media-placeholder__button').click();
    
    			}
    		}

    that code runs on DOMNodeInserted

  • The topic ‘how to trigger the click event of a Gutenberg block button’ is closed to new replies.