can anyone help me? i've got a silly question. i try to make an alert function using js but it doesnt execute
<script type="text/javascript">
$(".delete").click(function(){
alert("Are you sure?");
});
</script>
and this is my delete button
<td><a class=\"btn delete btn-danger\" href='".base_url().'admin/blog/deleteblog/1'."'>Delete</a></td>
It seems to work fine in the example below for me.
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<td><a class="btn delete btn-danger" href="#">Delete</a></td>
</body>
<script>
$(".delete").click(function () {
alert("Are you sure?");
});
</script>
</html>
I'm unsure why you have used the \ around your class name here, but one is within the quotes and one outside. I would remove these.
"btn delete btn-danger"
<td>
<a class="btn delete btn-danger" href='".base_url().'admin/blog/deleteblog/1'."'>
Delete
</a>
</td>
As for your script, you should check if the document is ready before using JQuery - https://learn.jquery.com/using-jquery-core/document-ready/
<script type="text/javascript">
$( document ).ready(function() {
$(".delete").click(function(){
alert("Are you sure?");
});
});
</script>