Unable to get JQuery to work in the backend
-
I am trying to customize a plugin (https://github.com/QuizandSurveyMaster/quiz_master_next ) . The plugin has a form in the backend which lets you create questions and its answers with different types of options for the question . This form has a drop down ( screenshot below) : https://drive.google.com/file/d/1FR0kUMJBc98KfG06u9_-q4Cn2pIv6nLc/view?usp=sharing . When a particular <option> is chosen from the drop down I want to append another drop down to the form . To do this I am trying to use my own Jquery script .
Here is the code which creates the question settings form in the plugin:
function qsm_settings_questions_tab() { global $mlwQuizMasterNext; $mlwQuizMasterNext->pluginHelper->register_quiz_settings_tabs( __( 'Questions', 'quiz-master-next' ), 'qsm_options_questions_tab_content' ); } add_action( 'plugins_loaded', 'qsm_settings_questions_tab', 5 );
I am enqueing my Jquery script in the qsm_options_questions_tab_content() function like below :
function qsm_options_questions_tab_content() { wp_enqueue_script( 'micromodal_script', plugins_url( '../../js/micromodal.min.js', __FILE__ ) ); // This is my Jquery script wp_enqueue_script( 'min_max', plugins_url( '../../js/minmax.js', __FILE__ ) , array() , false, true ); wp_enqueue_script( 'qsm_admin_question_js', plugins_url( '../../js/qsm-admin-question.js', __FILE__ ), array( 'backbone', 'underscore', 'jquery-ui-sortable', 'wp-util', 'micromodal_script', 'qmn_admin_js' ), $mlwQuizMasterNext->version, true ); }
I am seeing my JS being loaded at the end after the Jquery core being loaded in the HTML source code like below :
<script type='text/javascript' src='https://localhost/testwp/wp-admin/load-scripts.php?c=1&load%5B%5D=jquery-core,jquery-migrate,utils&ver=5.2.9'></script>
<script type='text/javascript' src='https://localhost/testwp/wp-content/plugins/quiz_master_next-master/php/admin/../../js/minmax.js?ver=5.2.9'></script>
However , JQuery selectors doesnt seem to work at all allthough vanilla Javascipt is working all right ( console.log(“hi”) in the below code . The Jquery script is intended to be triggered on change of select drop down . Here is the code :
jQuery(function () { console.log("hi"); jQuery('#question_type').on('change', function() { alert( this.value ); console.log('hi'); jQuery('#testbutton').on('click' , function() { console.log("hi"); }); }); });
For testing purposes I had a button inserted in the form and even a simple Jquery on click is failing . Could someone please provide any pointers as to why Jquery is not working ?
- The topic ‘Unable to get JQuery to work in the backend’ is closed to new replies.