• Resolved sababaa

    (@sababaa)


    Hi,

    How it’s possible to add an active class on “cookie-law-info-bar” div ?

    I already tried this, it’s work but active class stay when the bar disappear :

    if(jQuery(cli_bar).length < 0) {
     jQuery('#cookie-law-info-bar').addClass('cli-bar-active');
    }

    I want an active class on “cookie-law-info-bar”, to move an another div when “cookie-law-info-bar” is shown or hidden.

    I’ve already tried code below to detect display none, no success too :
    if $('#cookie-law-info-bar').css('display') == 'none') {

    Regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author WebToffee

    (@webtoffee)

    Hi @sababaa,

    Please try using below code snippet.

    add_action('wp_head', 'cli_add_bar_class', 9);
    function cli_add_bar_class() {
    	if (class_exists('Cookie_Law_Info_Public')) {
    	?>
    		<script type="text/javascript">
    			jQuery(document).ready(function() {
    				if (jQuery('#cookie-law-info-bar:visible').length > 0) {
    					jQuery('#cookie-law-info-bar').addClass('cli-bar-active');
    				}
    				//remove class after consent
    				jQuery('.cli_action_button').click(function(e) {
    					e.preventDefault();
    					if (jQuery(this).attr('data-cli_action') == 'accept') {
    						jQuery('#cookie-law-info-bar').removeClass('cli-bar-active');
    					}
    				});
    			});
    		</script>
    <?php
    	}
    }
    Thread Starter sababaa

    (@sababaa)

    Hi,

    The code do what i want, thank you!

    Another question, when i want to detect if “cookie-law-info-bar” has class “cli-bar-active”, my js don’t work.

    In console, this return false:
    console.log(jQuery('#cookie-law-info-bar').hasClass('cli-bar-active'));

    If i try another class, it’s return true:
    console.log(jQuery('.bt-form-sticky').hasClass('bt-form-sticky'));

    My full code :

    $(document).ready(function() {
      if (jQuery('#cookie-law-info-bar').hasClass('cli-bar-active')) {
        jQuery('.bt-form-sticky').toggleClass('test');
      }
    });
    Plugin Author WebToffee

    (@webtoffee)

    Hi @sababaa,

    Please share your site URL.

    Thread Starter sababaa

    (@sababaa)

    My website can’t be share before launching. It’s a private project, sorry.

    No error in console, no cache system.

    Some screenshot to help you :
    https://i.gyazo.com/ff52c65fd87c6c0bf04603483afbc69a.png
    https://i.gyazo.com/6e7578bc18d29a91a1832349183a8219.png

    Thread Starter sababaa

    (@sababaa)

    Hi,

    Finally, with your code, i wroted something more easy :

    add_action('wp_head', 'cli_add_bar_class', 9);
    function cli_add_bar_class() {
    	if (class_exists('Cookie_Law_Info_Public')) {
    	?>
    		<script type="text/javascript">
    			jQuery(document).ready(function() {
    				if (jQuery('.cli-bar-container:visible').length > 0) {
              jQuery('.bt-form-sticky').addClass('test');
    				}
    				//remove class after consent
    				jQuery('.cli_action_button').click(function(e) {
    					e.preventDefault();
    					if (jQuery(this).attr('data-cli_action') == 'accept') {
                jQuery('.bt-form-sticky').removeClass('test');
    					}
    				});
    			});
    		</script>
    <?php
    	}
    }

    I’he just had my class “test” on the div who need to move.

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Class active on “cookie-law-info-bar”’ is closed to new replies.