简体   繁体   中英

hide a specific div from html ajax response

I am not experimented with ajax.

I have this html ajax response and I want to hide the first div 'loading' after ajax success

Response :

<div id="loading">
  <label>..</label>
  <div>...</div>
</div>
<div id="list">
...
...
</div>

I have tried a lot of things :

success: function (response) {
  response.find('#loading').html().hide();
  response.filter('#loading').hide();
  response.find('#loading').hide();
}

But that does not work.

通过其ID直接隐藏对象:

$('#loading').hide()

css:

.hidden { display: none; }

js:

$.ajax({})
  .done(function(data){
    var html = $(data);
    html.find('#loading').addClass('hidden');
    $('document').append(html);
  }
);

 <div id="loading"> <p>Test</p> </div> <button onclick="test()"/> <script> function test() { document.getElementById("loading").style.display = "none"; } </script> 

you must add your response in DOM:

$(body).html(response);

then you can hide you div :

$("#loading").hide();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM