Mukesh Kumar Bijarniya
Mukesh Kumar Bijarniya

Reputation: 466

remove array element in jquery

i have an dynamic array of multiple checkboxes. when i checked any checkbox then it get its value and put this in array. i want when i uncheck this then value of this checkbox remove from array. thnku..

$(document).ready(function (e) {
    var myCheckboxescolour = new Array();
    var myCheckboxesprice = new Array();
    var mycolour;
    var myprice;
    $(".searchcheck").click(function () {
        mycolour = '';
        myprice = '';
        if ($(this).attr('title') == 'colour') {
            if (this.checked == true) {
                myCheckboxescolour.push($(this).val());
            } else {
                if (jQuery.inArray($(this).val(), myCheckboxescolour)) {
                    myCheckboxescolour.pop($(this).val());
                }
            }
        })
    };

Upvotes: 0

Views: 103

Answers (1)

Sajuna Fernando
Sajuna Fernando

Reputation: 1384

var removeValue = $(this).val();

myCheckboxescolour = jQuery.grep(myCheckboxescolour, function(value) {
     return value != removeValue;
     });

Upvotes: 1

Related Questions