J
J
jackie chan2015-11-13 20:10:54
PHP
jackie chan, 2015-11-13 20:10:54

How to clear class and id?

Hello everyone again, the problem is)
The bottom line is that when loading, a code is executed that fills the ul class with li elements using php, there is a js script that also fills the ul class with li elements during its work, but adds its entries to the end of the entire list, the question is how to clear the list if Is this or that code being executed?
here is the 1 fill code

<?php //Вывод аудио 
    if (!empty($audio['response']['items'])) { ?>
        <?php foreach ($audio['response']['items'] as $item) { ?>
     <li><a href="<?= $item['url'] ?>"><b><?= $item['artist'] ?></b> - <?= $item['title'] ?> <span class="label"><?= $item['aid'] ?></span></a></li>
        <?php } ?>
    <?php } ?>

And here is the actual 2 fill code
<script type="text/javascript">
    VK.init({
        apiId: 5135424
    });
  function recommendate(){
    VK.Api.call('audio.getRecommendations', {count: '1000'}, function(r) {
      if(r.response) {
        $('#playlist').append('<li><a href="'+r.response[0].url+'"><b>'+r.response[0].artist+'</b> - '+r.response[0].title+'<span class="label">'+r.response[0].aid+'</span></a></li>')       
      }
    });
  };
</script>

Here is the same ul in which everything is filled<ul class="sm2-playlist-bd" id="playlist">

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
LinGG, 2015-11-13
@onvorobyov

judging by the JS code, it pulls 1000 records and inserts only the first one? what is the question at all?

S
Stalker_RED, 2015-11-13
@Stalker_RED

$('#playlist').htm('')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question