我如何删除使用AJAX获得的元素?

问题描述 投票:0回答:1

我正在使用AJAX获得元素,但是现在,我只想在函数“ click”中将其删除,但是它不起作用,我的页面正在更改。

这是我的代码,我正在尝试使用“ hide”或“ fadeOut”将其删除。我到底该怎么做?

$(function(){

  $('#send__mail').on('click', function(e){
    e.preventDefault();
    $('.mail').fadeIn('fast');
    var email = $(this).attr('href');
    $.ajax({
      url:email,
      type:'GET',
      success:function(html){
        $('.mail__content').html(html);
      }
    });
  });

});
javascript jquery html dom
1个回答
0
投票

[不确定您的“我的页面正在改变”的意思,也不清楚要在处理程序中隐藏的内容。猜测您正在尝试隐藏使用给定处理程序发送电子邮件的按钮,只需对其进行以下更改,就应该隐藏该按钮。

尝试:

$(function(){

  $('#send__mail').on('click', function(e){
    e.preventDefault();
    $('.mail').fadeIn('fast');
    var email = $(this).attr('href');
    $.ajax({
      url:email,
      type:'GET',
      success:function(html){
        $('.mail__content').html(html);
      }
    });

   $(this).hide(); //this will hide the button that triggered this click handler

  }); 
© www.soinside.com 2019 - 2024. All rights reserved.