Using jQuery with the Block editor?
-
It’s possible to use jQuery in the admin area and with the Classic Editor. But what about with the Block Editor, which is built with React?
I’m trying to set the time for each post to 8am when the Date/Time dialog is opened.
I’m using this jQuery (and with a cookie to check if 8am has already been set, and that code is not shown for simplicity) to toggle the AM button when the Date/Time dialog is opened.
jQuery(document).on( 'click', '.editor-post-schedule__dialog-toggle', function () {
jQuery('.components-datetime__time-am-button').click();But jQuery doesn’t work with the hours and minutes fields:
jQuery(document).on( 'click', '.editor-post-schedule__dialog-toggle', function () {
jQuery('input[min="1"][max="12"].components-input-control__input').val('08').trigger("change");
jQuery('input[min="0"][max="59"].components-input-control__input').val('00').trigger("change");
});jQuery is not able to fully interact with React. Using
jQuery(document).ready(function()doesn’t make a difference.How can I set the time to 8am on each post when the Date/Time dialog is opened? Is there a way to do this with jQuery and React?
Or should it be done with only React?
Or should I hook into a function with PHP?
The topic ‘Using jQuery with the Block editor?’ is closed to new replies.