By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

jquery fails to make a div empty

P: 12
In my asp.net mvc 4 application, i am loading a partial view in current page. The code successfully loads the desired partial view in <div id="PartialContent"></div> on the current page. But, before sending jquery ajax request to the server, i am trying to clear the div. But the div is not clearing. The old content is still there until the new content arrives. Here is my code-

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.     $(document).ready(function () {
  3.         $(".mainnav a").click(function (e) {
  4.             e.preventDefault();
  5.             var url = $(this).attr('href');
  6.             if (url != '#') {
  7.                 $('#PartialContent').empty(); //not working 
  8.                 $('#PartialContent').html(''); //not working 
  9.                 $('div#PartialContent').children().remove(); //not working 
  10.                 $.get(url, function (response) {
  11.                     $('#PartialContent').html(response);
  12.                 });
  13.             }
  14.         });
  15.     });
  16. </script>
Any idea to solve it?
Nov 8 '13 #1
Share this Question
Share on Google+
1 Reply


Exequiel
100+
P: 287
put your $('#PartialContent').html(""); inside of your $.get function.
Expand|Select|Wrap|Line Numbers
  1.  $.get(url, function (response) {
  2.    $('#PartialContent').html("");
  3.    $('#PartialContent').html(response);
  4.  });
  5.  
Nov 11 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.