Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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
HTML
<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-
JavaScript
$(document).ready(function () {
    $(&quot;.mainnav a&quot;).click(function (e) {
        e.preventDefault();
        var url = $(this).attr(&#39;href&#39;);
        if (url != &#39;#&#39;) {
            $(&#39;#PartialContent&#39;).empty(); //not working
            $(&#39;#PartialContent&#39;).html(&#39;&#39;); //not working
            $(&#39;div#PartialContent&#39;).children().remove(); //not working
            $.get(url, function (response) {
                $(&#39;#PartialContent&#39;).html(response);
            });
        }
    });
});


any idea?
Posted
Updated 8-Nov-13 5:56am
v2
Comments
Sergey Alexandrovich Kryukov 8-Nov-13 10:46am    
Can you use the debugger? Check up if click handler is invoked, then if "url != ..." condition evaluates to true...
—SA

Just use the hide() is as below.

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


When data comes (inside the success event) use show() method is as below.

$( "#PartialContent" ).show();
 
Share this answer
 
try this
JavaScript
$('#PartialContent').empty();
or
$('#PartialContent').html('');
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900