javascript - Uncaught ReferenceError: element is not defined - Stack Overflow

I have created a delete button that deletes a row from my database using jquery and ajax. when i click

I have created a delete button that deletes a row from my database using jquery and ajax. when i click the button i get the error : Uncaught ReferenceError: element is not defined.

It then higlights var del_id = element.attr("id");

 <a href="#" id="14" class="delbutton"><i class ="fa fa-trash"></i></a>


<script type="text/javascript">
    $(function() {

    $(".delbutton").click(function(){
    var del_id = element.attr("id");
    var info = 'id=' + del_id;
    if(confirm("Sure you want to delete this?"))
    {
    $.ajax({
    type: "POST",
    url: "feed/deletepost",
    data: info,
    success: function(){
    }
    });
    $(this).parents(".record").animate({ backgroundColor: "#fbc7c7" }, "fast")
    .animate({ opacity: "hide" }, "slow");
    }
    return false;
    });
    });
</script>

Any ideas on what could be causing this?

I have created a delete button that deletes a row from my database using jquery and ajax. when i click the button i get the error : Uncaught ReferenceError: element is not defined.

It then higlights var del_id = element.attr("id");

 <a href="#" id="14" class="delbutton"><i class ="fa fa-trash"></i></a>


<script type="text/javascript">
    $(function() {

    $(".delbutton").click(function(){
    var del_id = element.attr("id");
    var info = 'id=' + del_id;
    if(confirm("Sure you want to delete this?"))
    {
    $.ajax({
    type: "POST",
    url: "feed/deletepost",
    data: info,
    success: function(){
    }
    });
    $(this).parents(".record").animate({ backgroundColor: "#fbc7c7" }, "fast")
    .animate({ opacity: "hide" }, "slow");
    }
    return false;
    });
    });
</script>

Any ideas on what could be causing this?

Share Improve this question edited Jan 25, 2018 at 20:53 Scott O'connor asked Jan 25, 2018 at 20:51 Scott O'connorScott O'connor 1331 gold badge1 silver badge9 bronze badges 2
  • 5 Well, the error is pretty self-explanatory. You don't define element. – TimoStaudinger Commented Jan 25, 2018 at 20:52
  • What are you expecting element to be? – Huangism Commented Jan 25, 2018 at 20:55
Add a ment  | 

1 Answer 1

Reset to default 4

This is because element is not defined :D try this instead:

$(".delbutton").click(function(){
  var del_id = $(this).attr("id");....

greetings

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742337710a4424985.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信