3

I was wondering would there be a way for me for do a check if an id exist and if exist do my function then check if next id exist

an example: if log2627251 exist do my function then check or wait for log2627252 exist then do function and keep going

var checkExist = setInterval(function() {
   if ($('#log2627251').length) {
      console.log("if exists do function then find next id");
      clearInterval(checkExist);
   }
}, 100);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<li id="log2627251" data="2627251" class="ch_logs">Text</li>

<li id="log2627252" data="2627252" class="ch_logs">Text</li>

<li id="log2627253" data="2627253" class="ch_logs">Text</li>

<li id="log2627254" data="2627254" class="ch_logs">Text</li>

sorry bad english

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Memoz
  • 39
  • 2
  • Not entirely sure what you're asking. Using jquery, checking the length of the selector response should work. – Jacques ジャック Aug 15 '18 at 18:15
  • You mean you would like to use a variable to encapsulate your value and see if the variable has a value in it before going on with your IF statement? – Chris Aug 15 '18 at 18:15
  • Side note: `data="2627251"` if you are trying to make a data attribute, it should have a key in the form of `data-key`, rather than just `data` – Taplar Aug 15 '18 at 18:24
  • What exactly are you wanting to do when they all exist? If you are simply waiting for them to all exist, you could do a selector for them all, and check that the length equals the total number of elements you are checking for. – Taplar Aug 15 '18 at 18:25
  • @Taplar ok, I've reopened it. – Rory McCrossan Aug 15 '18 at 19:03

0 Answers0