You need to listen for the click
event (there is no such thing as a pre/before click) and do some work right then or figure out if you want to allow the click
to “go through” or not based on some validation for example.
jQuery(function($) {
// We are binding to the body so that the code
// will work for future elements added to the DOM
$('body').on('click', '.widget-control-save', function(ev) {
var my_validation = true;
if ( my_validation ) {
console.log('widget save!');
} else {
ev.preventDefault();
ev.stopPropagation(); /* We are capturing the event so it won't bubble up. */
}
})
});