jquery无法使div空 [英] jquery fails to make a div empty

查看:52
本文介绍了jquery无法使div空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的asp.net mvc 4应用程序中,我正在当前页面中加载局部视图。代码在

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>

。但是,在向服务器发送jquery ajax请求之前,我正在尝试清除div。但是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-

$(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?

推荐答案

document )。ready( function (){
(document).ready(function () {


(& quot ; .mainnav a& quot;)。click( function (e){
e.preventDefault();
var url =
(&quot;.mainnav a&quot;).click(function (e) { e.preventDefault(); var url =


this )。attr(&#39; href&# 39;);
如果(url!=&#39;#&#39;){
(this).attr(&#39;href&#39;); if (url != &#39;#&#39;) {


这篇关于jquery无法使div空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆