There are several blocks of the same name, inside which there is a value "is" and "no", if the value is "no", then the button element should be hidden, and so in the code below everything works, but if we write like this:

var thereis = $(this).find(".onechild").text(); 

then it stops working, although the value of the variable thereis is still no different

  $(".sibline").each(function(i) { var thereis = $(this).find(".onechild .val").text(); if (thereis == 'Нет') { $(".sibline").find(".twochild").eq(i).css('display', 'none'); } }) 
 .onechild { display: inline-block; position: relative; margin: 2px; padding: 3px; background: #ccc; } .twochild { display: inline-block; background: #CDDC39; padding: 3px; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <div class="sibline"> <div class="onechild"> <div class="val">Есть</div> </div> <div class="twochild"> <div class="val">Кнопка</div> </div> </div> <div class="sibline"> <div class="onechild"> <div class="val">Нет</div> </div> <div class="twochild"> <div class="val">Кнопка</div> </div> </div> <div class="sibline"> <div class="onechild"> <div class="val">Есть</div> </div> <div class="twochild"> <div class="val">Кнопка</div> </div> </div> <div class="sibline"> <div class="onechild"> <div class="val">Есть</div> </div> <div class="twochild"> <div class="val">Кнопка</div> </div> </div> 

    1 answer 1

    With

     var thereis = $(this).find(".onechild").text(); 

    thereis not equal to 'Is', but equal to a word with four spaces (tab) and a line break.

     <div class="onechild">(перенос строки тут) (4 пробела тут)<div class="val">Есть</div> </div> 

    enter image description here

    • How was it checked? output to the console or the body of the page? - Yevgeny Shevtsov
    • @ YevgenyShevtsov, You can immediately see from the console, high fields for one word - Mr. Black
    • @YevgeniyShevtsov, always use the function String.prototype.trim for such cases, but it is better to implement this with the help of an attribute-type flag: data-visible=1 . - user207618
    • That is, the value "is", "no" is placed in the attribute? String.prototype.trim, but it’s really useful to know more) - Evgeny Shevtsov
    • @ EvgenyShevtsov, I would do just that. And Other meant to find an alternative to the jquery text () method for the similarity of trim - Mr. Black