0

I have the following code

value.bind( function( to ) {
    $( '#header.alt.reveal' ).attr('style', 'background:transparent;', to );

It's placed in a function that adds the attribute when a checkbox is checked. However, I want to make this toggle so that when it is unchecked the attribute is removed. Can someone explain how I do this please

For a bit of context - this is the js file that controls real time changes in the wordpress customizer - the whole of this snippet looks like this:

// FRONT PAGE MENU TRANSPARENCY
wp.customize( 'front_page_menu_transaprency', function( value ) {
    value.bind( function( to ) {
        $( '#header.alt.reveal' ).toggle.attr('style', 'background:transparent;', to );

    });
});
4
  • What is the purpose of parameter to??? Commented Apr 29, 2014 at 15:08
  • @A.Wolff just added a bit of context to the question, thanks Commented Apr 29, 2014 at 15:09
  • Thx for update but i'm afraid, i don't know wp :( Commented Apr 29, 2014 at 15:11
  • @SamSkirrow According the documentation of Jquery, there are only two parameters for the method .attr(). For what stays the third parameter? Commented Apr 29, 2014 at 15:17

2 Answers 2

2

I believe you're looking for something as follows:

$(".checkbox").click(function(){
   if($(this).is(':checked')){
       $('#header.alt.reveal').addClass('classname');
   }else{
       $('#header.alt.reveal').removeClass('classname');
   }
});
Sign up to request clarification or add additional context in comments.

1 Comment

I was totally misunderstanding the question. You could make this a little less repetitive by doing: $('#header.alt.reveal').toggleClass('classname', this.checked);
1

I believe you're looking for something like this. I'm just changing the background color to red when something is true.

$('#header.alt.reveal').css('background-color', function () {
  return to ? '#f00' : 'transparent';
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.