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
1 Answer
Reset to default 4This 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条)