2

How can I do a display none in div with id="NoveMeses" if all elements from h3 show "N.A"?

If h3 from div row1 and row2 show me the span="N.A", I want to display none the div NoveMeses.

There is my code using AngularJs

<div id="NoveMeses" data-ng-if=$odd class="tableRowOdd" data-ng-show="item.TipoOWS === '9M'">
          <div class="tableCellContent20">
                   <h3 class="cellTextType" ><span>{{::item.TipoCalculado.split('#')[1]}}</span></h3>
          </div>

          <div id="row1" class="tableCellContent20">
                   <h3 class="cellTextValue" data-ng-show="item.TipoOWS !== 'Datas'"><span>{{::item.Last.replace('.',',') | limitTo:7:0}}</span></h3>
                   <h3 class="cellTextValue" data-ng-show="!item.TipoOWS !== 'Datas'"><span>N.A.</span></h3>
          </div>

          <div id="row2" class="tableCellContent20">
                   <h3 class="cellTextValue" data-ng-show="item.TipoOWS !== 'Datas'"><span>{{::item.LastUm.replace('.',',') | limitTo:7:0}}</span></h3>
                   <h3 class="cellTextValue" data-ng-show="!item.TipoOWS !== 'Datas'"><span>N.A.</span></h3>
          </div>

</div>
1

I haven't tested this, but you could do something similar to below. It gets all <h3> elements from your <div id="NoveMess">, counts them, then checks if each is equal to "N.A".

jQuery:

var trueList = [];
$(".NoveMess h3").each(function(){
    trueList.push( (this.textContent.trim() === "N.A") );
});
if( trueList.includes(false) )
    $(".NoveMess").hide();

Vanilla Javascript:

var trueList = [];
var parentContainer = document.getElementsByClassName("NoveMess")[0];
var childH3Containers = parentContainer.getElementsByTagName("H3");

for(var text in childH3Containers){
    trueList.push( (text.textContent.trim() === "N.A") )
}

if( trueList.includes(false) )
    parentContainer.style.display = "none";

Again, these are untested, but I believe the concept is sound.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.