How do you remove the block class when you retook it?



  • Hello! There are blocks (on each one of their ids) that are added to the class. Block number one pressed the class. Block No. 2 was added to the class, and the class was removed from block No. 1. That's right. But it is necessary that, when repressed to the block, the unit removes the class, i.e. pressed on block No. 1, the class is added, pressed again - the class is removed. Help me, please.

    $(document).ready(function(){
        $('.map-marker').on('click', function() {
            var $me = $(this);
            var id = $me.data("id");
    
    var $tab = $('.map-marker[data-id=' + id + ']');
    var $tabBody = $('.map-bubble[data-id = ' + id + '-content]');
    
        $('.map-marker').removeClass('is-open');
        $('.map-marker[data-id=' + id + ']').addClass('is-open');
    
        $('.map-bubble').removeClass('is-visible');
        $('.map-bubble[data-id = ' + id + '-content]').addClass('is-visible');
    
    });
    

    });



  • This case needs to be used http://api.jquery.com/toggleclass/ Two elements straight away: active now and the one that's clicked. A method may be used for integration http://api.jquery.com/add/#add-selector

    For example:

    $(document).ready(function(){
        $('.map-marker').on('click', function() {
            var $me = $(this);
            var id = $me.data("id");
    
    var $tab = $('.map-marker[data-id=' + id + ']');
    var $tabBody = $('.map-bubble[data-id = ' + id + '-content]');
    
        $('.map-marker.is-open').add(this).toggleClass('is-open');
    
        $('.map-bubble.is-visible').add('.map-bubble[data-id = ' + id + '-content]').toggleClass('is-visible');
    
    });
    

    });




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2