admin管理员组文章数量:1130349
I want to bind a click event to Wordpress custom control (Theme Customizer). I have tried with (customizer.js):
$(document).on('click', '.element_class', function () {
console.log(5);
});
, but it doesn't bind.
The control is something like :
<div class="element_class">
Value
</div>
functions.php:
function customizer_live_preview() {
wp_enqueue_script(
'theme-customizer',
get_stylesheet_directory_uri() . 'customizer.js',
array( 'customize-preview' ), '0.1.0', true);
}
add_action( 'customize_preview_init', 'customizer_live_preview' );
I want to bind a click event to Wordpress custom control (Theme Customizer). I have tried with (customizer.js):
$(document).on('click', '.element_class', function () {
console.log(5);
});
, but it doesn't bind.
The control is something like :
<div class="element_class">
Value
</div>
functions.php:
function customizer_live_preview() {
wp_enqueue_script(
'theme-customizer',
get_stylesheet_directory_uri() . 'customizer.js',
array( 'customize-preview' ), '0.1.0', true);
}
add_action( 'customize_preview_init', 'customizer_live_preview' );
Share
Improve this question
asked Oct 21, 2018 at 22:04
gdfgdfggdfgdfg
1721 silver badge15 bronze badges
1
- Check with below $('.element_class').on('click', function(event) { console.log(5); }); – Mehul Commented Oct 22, 2018 at 11:29
1 Answer
Reset to default 0You need to enqueue a separate script on a different action with a different dependency.
/**
* Enqueue styles and scripts for the Customizer pane.
*/
function mytheme_customize_pane_enqueue() {
wp_enqueue_script( 'mytheme-customizer-control',
get_template_directory_uri() . '/js/customizer-control.js',
array( 'customize-controls' ), '20180924', true );
}
add_action( 'customize_controls_enqueue_scripts', 'mytheme_customize_pane_enqueue' );
The JS looks like this:
( function( wp, $ ) {
wp.customize.control( 'mytheme_option', function( control ) {
control.container.on( 'click', '.element_class', function( event ) {
event.stopPropagation();
//control.doNotice( '' );
//control.applyPresetValues( $( this ).data( 'revert' ) );
} );
} );
} )( wp, jQuery );
I want to bind a click event to Wordpress custom control (Theme Customizer). I have tried with (customizer.js):
$(document).on('click', '.element_class', function () {
console.log(5);
});
, but it doesn't bind.
The control is something like :
<div class="element_class">
Value
</div>
functions.php:
function customizer_live_preview() {
wp_enqueue_script(
'theme-customizer',
get_stylesheet_directory_uri() . 'customizer.js',
array( 'customize-preview' ), '0.1.0', true);
}
add_action( 'customize_preview_init', 'customizer_live_preview' );
I want to bind a click event to Wordpress custom control (Theme Customizer). I have tried with (customizer.js):
$(document).on('click', '.element_class', function () {
console.log(5);
});
, but it doesn't bind.
The control is something like :
<div class="element_class">
Value
</div>
functions.php:
function customizer_live_preview() {
wp_enqueue_script(
'theme-customizer',
get_stylesheet_directory_uri() . 'customizer.js',
array( 'customize-preview' ), '0.1.0', true);
}
add_action( 'customize_preview_init', 'customizer_live_preview' );
Share
Improve this question
asked Oct 21, 2018 at 22:04
gdfgdfggdfgdfg
1721 silver badge15 bronze badges
1
- Check with below $('.element_class').on('click', function(event) { console.log(5); }); – Mehul Commented Oct 22, 2018 at 11:29
1 Answer
Reset to default 0You need to enqueue a separate script on a different action with a different dependency.
/**
* Enqueue styles and scripts for the Customizer pane.
*/
function mytheme_customize_pane_enqueue() {
wp_enqueue_script( 'mytheme-customizer-control',
get_template_directory_uri() . '/js/customizer-control.js',
array( 'customize-controls' ), '20180924', true );
}
add_action( 'customize_controls_enqueue_scripts', 'mytheme_customize_pane_enqueue' );
The JS looks like this:
( function( wp, $ ) {
wp.customize.control( 'mytheme_option', function( control ) {
control.container.on( 'click', '.element_class', function( event ) {
event.stopPropagation();
//control.doNotice( '' );
//control.applyPresetValues( $( this ).data( 'revert' ) );
} );
} );
} )( wp, jQuery );
本文标签: customizationBind JS event to Wordpress control customizer
版权声明:本文标题:customization - Bind JS event to Wordpress control customizer 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749024215a2304846.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论