There is such a block:

<div id="key-<?=$key["id"]; ?>"> ... </div> 

When you click on the button. which is in the middle of the code. This block is removed. (There is a data-id that I take with the help of attr - $('#key-${id}').remove(); ). After deleting, I want to know if there are any more such blocks with a similar id . I think something to do through the regular season. I think something like this:

if ($("*").is('#key-${/^[1-9]{1}[0-9]*/}')) { ... } - but it gives an error

thank

  • После удаления, хочу узнать есть ли еще такие блоки с подобным id I did not understand, do you have several elements with the same id attributes on the page? - neluzhin

1 answer 1

You can do it without a regular basis, by checking the beginning of the attribute :

 $(function() { $('button#del').click(function() { $('div').remove(); }); $('button#has').click(function() { if($('[id^="key-id-"]').length > 0){ alert('Есть'); }else{ alert('Нету'); }; }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="key-id-1">0</div> <div id="key-id-2">1</div> <div id="key-id-3">2</div> <div id="key-id-4">3</div> <div id="key-id-5">4</div> <button id="del">Удалить</button> <button id="has">Проверить</button>