on/off button (switch button) through edit button hide and show
<p>I create category module and I put switch button like active or deactive category. I used codeigniter framework.</p>

<p>My question: I checked button then edit button show and unchecked button then hide edit button.</p>

<p><strong>Controller:</strong></p>

<pre><code>class Category extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this-&gt;load-&gt;model('category_model');
        $this-&gt;load-&gt;library('form_validation');
    }
  public function index() {
        if (!empty($_SESSION['admin'])) {
            $data = array(
                'page_title' =&gt; 'Category',
                'page_name' =&gt; 'category/index',
                'result' =&gt; $this-&gt;category_model-&gt;list_all()
            );
            $this-&gt;load-&gt;view('template', $data);
        } else {
            redirect('login');
        }
    }

public function update_cat_status() {
        $data = $this-&gt;category_model-&gt;update_cat_status($_GET);
        echo json_encode($data);
    }

 public function edit($id) {
        if (!empty($_SESSION['admin'])) {
            $this-&gt;form_validation-&gt;set_rules('cat_name', 'Category Name', 'required');
            if ($this-&gt;form_validation-&gt;run() == FALSE) {
                $data = array(
                    'page_title' =&gt; 'Edit Category',
                    'page_name' =&gt; 'category/edit',
                    'error' =&gt; validation_errors(),
                    'result' =&gt; $this-&gt;category_model-&gt;select_id($id),
                    'id' =&gt; $id
                );
                $this-&gt;load-&gt;view('template', $data);
            } else {
                $this-&gt;category_model-&gt;update($_POST, $id);
                redirect('category');
            }
        } else {
            redirect('login');
        }
    }
}
</code></pre>

<p><strong>View:</strong></p>

<pre><code>&lt;table id="example" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%"&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Category Name&lt;/th&gt;
      &lt;th&gt;Status&lt;/th&gt;
      &lt;th&gt;Edit&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;?php foreach ($result as $value): ?&gt;
                                    &lt;tr&gt;
                                        &lt;td&gt;&lt;?= $value['name']; ?&gt;&lt;/td&gt;
                                        &lt;td&gt; &lt;div class="onoffswitch"&gt;
                                                &lt;input type="hidden" value="&lt;?php echo $value["id"]; ?&gt;"/&gt;
                                                &lt;input type="checkbox" class="js-switch"
                                                &lt;?php
                                                if ($value['status'] == 1) {
                                                    echo "checked";
                                                }
                                                ?&gt;&gt;
                                            &lt;/div&gt;
                                        &lt;/td&gt;
                                        &lt;td&gt;&lt;a href="&lt;?= base_url("category/edit/{$value['id']}"); ?&gt;" class="btn btn-success"&gt;Edit&lt;/a&gt;&lt;/td&gt;
                                    &lt;/tr&gt;
                                &lt;?php endforeach; ?&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
</code></pre>

<p><strong>Model:</strong></p>

<pre><code>class Category_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }
public function insert($data) {
        $this-&gt;db-&gt;insert('category', array('name' =&gt; $data['cat_name'], 'created_on' =&gt; date("Y-m-d h:i:sa")));
    }

    public function list_all() {
        return $this-&gt;db-&gt;get('category')-&gt;result_array();
    }
}
</code></pre>

<p><strong>jquery:</strong></p>

<pre><code>$(document).ready(function () {
    //category switch
    $('.onoffswitch').change(function () {
        var cat_id = $(this).children(':hidden').val();
        if ($(this).children(':checked').length === 0)
        {
            var status = 0;
        }
        else
        {
            var status = 1;
        }
        $.ajax({
            type: 'GET',
            url: base_url + "category/update_cat_status",
            data: {status: status, cat_id: cat_id},
            success: function (response) {
                console.log(response);
            }
        });
    });
});
</code></pre>

<p><strong>Screenshot</strong></p>

<p><img src="https://i.stack.imgur.com/8CedL.jpg" alt="Screenshot"></p>