I am trying to make a timer on JS, and now I am trying to make adding a timer. I want to make sure that before adding an element, there is a check for the presence of such a string in ul. Tell me how to do it.

Thank you in advance!

  • if (document.querySelector ('ul li')) alert ('ul has li') - Stranger in the Q
  • No, you did not understand. I need to be checked for the presence of a DEFINED line. for example - "10 seconds". - Max Mazur
  • Add your markup to the question - Stranger in the Q

1 answer 1

Example:

function find(id) { let el = $('#list').find('li[id="'+id+'"]'); console.log(el); if($(el).length>0) { alert('найдено'); } else { alert('элемента нет'); } } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <ul id="list"> <li id="1">1</li> <li id="2">2</li> </ul> <input type="button" onclick="find(3)" value="Найти элемент с id=3" />