I'm trying to set focus to textbox in a modal using the code below:
$('#search-modal').on('shown.bs.modal', function () {
$('#s').focus();
});
this code is in script.js file which I add it using the code:
function dia_scripts() {
wp_enqueue_style( 'bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css', array(), '3.3.7' );
// checking to include Bootstrap rtl edit
if ( is_rtl() ) {
wp_enqueue_style( 'bootstrap-rtl', get_template_directory_uri() . '/css/bootstrap-rtl.min.css', array(), '3.3.7' );
}
wp_enqueue_style( 'style', get_template_directory_uri() . '/style.css' );
wp_enqueue_script( 'bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js', array( 'jquery' ), '3.3.7', true );
wp_enqueue_script( 'custom-script', get_template_directory_uri() . '/js/script.js', array( 'jquery' ), null, true );
}
add_action( 'wp_enqueue_scripts', 'dia_scripts' );
I found that jQuery -blank javascript is working- isn't working with script.js file. However, it's working well with bootstrap.min.js file. any ideas?
jQuery, not$, check your browser's error console for javascript errors.jQueryprefix, right?function($){ //code here }(jQuery);. This passes$as the object reference inside that function so you can use$.