javascriptjquerycsshideshow-hide

How to hide element if second element receive an specific class?


For example we have 2 button

First button <button class="arguments variation-one">Some text</button> - this button have dynamic classes like: variation-one, variation-two, variation-three, but class .arguments is static.

and Second button <button class="simple">Other text</button>

I must hide second button if first button receiving class .variation-two, without on click events. By js, jQuery, or even css if its possible. Please help me.

Im find similar problem on this forum and solution was this script

$(document).ready(function() {
    var $redTags = $('.lt-label');
    if($redTags.hasClass(".lt-offline") {
        $("#l-b-wrapper").hide();
    }
}

I tried to interpret it to suit my task, but nothing worked for me


Solution

  • Check if there's any buttons that has arguments and variation-two classes. If there's, hide the second button with simple class.

    $(document).ready(function() {
        let element = $(".arguments.variation-two");
        if(element.length > 0) {
            $(".simple").hide();
        }
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    
    <button class="arguments variation-two">Some Text</button> 
    <button class="simple">Other Text</button>