Amit
Amit

Reputation: 209

I am unable to use id in codeigniter for jquery

I have a submit button in codeigniter which is as follow:

<?php
  form_open('admin/delete_article'),
  form_hidden('article_id', $article->id),
  form_submit(['name'=>'submit', 'id'=>'btnDelete', 'value'=>'Delete', 'class'=>'btn btn-danger']),
  form_close();
  ?>

Actually this is a delete button and I want to add a fuctionality to confirm before delete, so I am using jquery by using #btnDelete, but that is not working. Source code is showing the input correctly, like:

<input type="submit" name="submit" value="Delete" id="btnDelete" class="btn btn-danger"  />

Jquery is loading correctly in the bottom of the page, but id and class of the input type is not working in jquery. My jquery code is as follow:

$(document).ready(function() {
    $("#btnDelete").click(function() {
        bootbox.confirm("Are you sure want to delete?", function(result) {
        alert("Confirm result: " + result);
        });
    });
 });

But id and class is not working even I am alerting something. Why is this so?

Update: This piece of code works:

$(document).ready(function(){
  $('div').click(function(){
      alert("Umar");
  });
});

I am unable to understand why any of the selectors of the input type is not working only, rest is working fine?

Upvotes: 1

Views: 56

Answers (1)

Mahmut D.
Mahmut D.

Reputation: 36

You can use this:

$('body').on('click', '#btnDelete', function() {
//code
});

Your code not working because it didn't load at the time, so can't catch the trigger.

Upvotes: 1

Related Questions