weixin_33690367 2011-05-16 16:06 采纳率: 0%
浏览 140

jQuery Ajax中的remove()

I am trying to get Ajax to remove an element within that same Ajax page. I make a call to a document via Ajax with the following code, but it doesn't remove the element:

<input type="text" value="test" name="someel" class="someelement" />
<script type="text/javascript">
    $('.someelement').remove();
</script>

I am using datatype = 'html' and other jquery stuff works, but it only works when I use things like the live function and I don't believe you can use that for removing elements, but I could be wrong.

Thanks.

EDIT:

Ajax Call:

$.ajax({        
    url: someurl,
    type: 'post',
    data: postvars,
    cache: false,
    dataType: "html",
    success: function (html) {
        $('#somediv').html(html);
    }
});

EDIT 2:

Example: REMOVED URL

  • 写回答

4条回答 默认 最新

  • weixin_33747129 2011-05-16 16:11
    关注

    You can't remove elements before they are loaded, so wait until the page is ready by using the jquery document ready function.

    <input type="text" value="test" name="someel" class="someelement" />
    <script type="text/javascript">
    $(document).ready(function() {
        $('.someelement').remove();
    });
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?