Home > Blockchain >  how to hide a div if another div has a special attribute
how to hide a div if another div has a special attribute

Time:06-11

I am a newbie, I have the following structure, what I want to achieve is that if the point class has the "black" attribute, the button does not appear. Someone who can help me please

     <div  > 

         <div  > 
           <div  > button </div>
            <div  > 
             <div value="black" > </div>
             <div value="white" > </div>
            </div>
           </div>
         </div> 


        if ($('.point').attr("value") == "black") {
              $(".button").hide();
         }

CodePudding user response:

Select everything with the class point which has a specific attribute (in this case value="black"). Then find the sibling of the parent div with the class .button and hide it. No need for the if statement.

$('.point[value="black"]').parent().siblings(".button").hide();
  • Related