Is it possible to implement a similar test? We have a div in which the values ​​will change, for example, 123 is displayed on one page, 4 on the second, 23 on the third, etc. On the page there is also a second div in which 5 more blocks are embedded. Such a thought, if in the first div the number 1 and 3 are inscribed, then the 1st and 3rd blocks are output, etc.

Sample HTML code to better understand the problem:

<div class="num">145</div> <div class="cont"> <div id="1">...</div> <div id="2" class="hide">...</div> <div id="3" class="hide">...</div> <div id="4">...</div> <div id="5">...</div> </div> 

That is, div.cont is a static block that does not change. On different pages only the numbers in div.num will change. Accordingly, if there are no any digits in this block, then the blocks with the corresponding id should hide or add a class to them.

    1 answer 1

     digs = $('.num').html(); $('.cont>div').each(function() { if (!digs.match($(this).attr('id'))) { $(this).addClass('hide'); } }); 
     .hide { display: none; } 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="num">145</div> <div class="cont"> <div id="1">1</div> <div id="2">2</div> <div id="3">3</div> <div id="4">4</div> <div id="5">5</div> </div> 

    • I will alter the script a bit, as the code was just an example, but the meaning is clear. Thank you very much! - Alexey Giryayev