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!
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!
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" />
Source: https://ru.stackoverflow.com/questions/958545/
All Articles