Onclick event not working | WordPress.org

[ad_1]

Hi,

This is AJ the theme author. For security reasons the plugin strips out any scripts from the customizer fields (this is very important). Rather then adding an inline script directly in the customizer what you’ll want to do is add the javascript to your site and then target the link.

If you are using a child theme the code would be added in your child theme’s functions.php file. If not, you would want to use some sort of “code snippets” plugin such as WPCode or Code Snippets.

Since you will be targeting the link/button with custom javascript you can of course use the included button if you’d like.

Here is what your code may look like for use with the included button:

add_action( 'wp_footer', function() { ?>
	<script>
		document.addEventListener( 'click', event => {
			if ( ! event.target.closest( '.easy-notification-bar-button a' ) ) {
				return;
			}
			if ( window.__lxG__consent__ !== undefined && window.__lxG__consent__.getState() !== null ) {
				window.__lxG__consent__.showConsent();
			} else {
				alert( 'This function only for users from European Economic Area (EEA)' );
			};
			event.preventDefault();
		} );
	</script>
<?php } );
  • This reply was modified 9 hours, 24 minutes ago by wpexplorer.

Hello, ok thanks for explanation.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer